INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Hello , I wrote a awk script , l

Hello , I wrote a awk script , l

(OP)
Hello ,

I wrote a awk script , line by line. each line is an awk one liner.
now I want to intergrate all lines into one AWK script.
I tried to do that for more than couple of hours but no success. each line runs perfect by itself... I must be doing sothing wrong here.

I would appricate your help:

ls -ltr --full-time -p | awk '{print $9, $6, $7}' > ~menyl/gg_list # takes all libs and files after sorting with full time
awk '{if ($1 ~/\//) {print} else {} }' ~menyl/gg_list > ~menyl/atf_list # remove all files that are not directories
awk 'BEGIN {FS= "." } 1==1 {print $1}' ~menyl/atf_list > ~menyl/array_list # remove the long time suffix
awk '{print $2, $3, $1}' ~menyl/array_list > ~menyl/finalarray_list # change the order of the fields
awk 'BEGIN {FS= "/" } 1==1 {print $1}' ~menyl/finalarray_list > ~menyl/finalarray_list2 ##






Thank you very much


meny

RE: Hello , I wrote a awk script , l

Do you need each of the output files or are they just holding the values while you proceed to the next step?

If not, this is each of your awk's concatenated:

CODE --> Commandline

ls -ltr --full-time -p | awk '{print $9, $6, $7}'|awk '{if ($1 ~/\//) {print} else {} }' |awk 'BEGIN {FS= "." } 1==1 {print $1}'|awk '{print $2, $3, $1}' |awk 'BEGIN {FS= "/" } 1==1 {print $1}' 

This writes the files as well, in case you need them.

CODE --> Commandline

ls -ltr --full-time -p | tee gg_list | awk '{print $9, $6, $7}'| tee atf_list | awk '{if ($1 ~/\//) {print} else {} }' | tee array_list | awk 'BEGIN {FS= "." } 1==1 {print $1}'| tee finalarray_list | awk '{print $2, $3, $1}' | tee finalarray_list2 | awk 'BEGIN {FS= "/" } 1==1 {print $1}' 

I am missing the point of this and not sure what your goal is but am happy to try and help.

If all you want is the output you could try:
This has the trailing forward slash and the second strips it in case you don't want it.

root@linux:/# ls -dlox --full-time */ | sed -e 's/.[0-9]\{9\}\>//g'|awk '{print $5" "$6" "$8}'
2012-07-06 18:36:18 bin/
2012-07-06 18:44:18 boot/
2012-08-11 08:03:20 dev/
2012-08-11 13:41:31 etc/
2012-07-06 18:53:08 home/
2012-07-06 18:39:04 lib/
2012-07-06 18:22:16 lost+found/
2012-08-11 08:03:05 media/
2012-05-07 10:55:35 mnt/
2012-07-07 10:54:10 opt/
2012-07-07 14:58:17 proc/
2012-08-11 13:41:33 root/
2012-08-11 07:54:22 sbin/
2010-07-21 02:55:22 selinux/
2012-07-06 18:24:36 srv/
2012-07-07 14:58:17 sys/
2012-08-12 16:17:01 tmp/
2012-07-06 18:24:36 usr/
2012-07-06 18:40:22 var/
root@linux:/# ls -dlox --full-time */ | sed -e 's/\(.*\)./\1/' -e 's/\.[0-9]\{9\}\>//g'|awk '{print $5" "$6" "$8}'
2012-07-06 18:36:18 bin
2012-07-06 18:44:18 boot
2012-08-11 08:03:20 dev
2012-08-11 13:41:31 etc
2012-07-06 18:53:08 home
2012-07-06 18:39:04 lib
2012-07-06 18:22:16 lost+found
2012-08-11 08:03:05 media
2012-05-07 10:55:35 mnt
2012-07-07 10:54:10 opt
2012-07-07 14:58:17 proc
2012-08-11 13:41:33 root
2012-08-11 07:54:22 sbin
2010-07-21 02:55:22 selinux
2012-07-06 18:24:36 srv
2012-07-07 14:58:17 sys
2012-08-12 16:17:01 tmp
2012-07-06 18:24:36 usr
2012-07-06 18:40:22 var



Cybex

RE: Hello , I wrote a awk script , l

(OP)
Hi again,

great answer! - thanks.
I dont need the intermidate files, so I would take the first option.
but what I was really asking is how to take my 5 singles lines, that each works fine , and
integrate them into an awk script that you can run from a terminal by typing >>awk -f some_script.awk..

thx

meny

RE: Hello , I wrote a awk script , l

Well either use the one-liner I showed you or create a new file called "awkscript.sh", chmod it to make it executable, paste this as the first line "#!/bin/bash", put your five individual scripts below it and save the file. Then you can run the script like this "./awkscript.sh" and it will run each of your five lines from one command. Is that what you were asking?

RE: Hello , I wrote a awk script , l

(OP)
Yes. that is exactly what I was asking!! works great.
but now Ive got few more question, if that is OK:

1. why the suffix is *.sh and not *.awk ?
2. I tried to do the same with awk suffix instaed of sh- and
it and wont work. why?

3. since the 5 different lines are all started with : awk..' isnt it possible to write is as one script, with one awk..'
can you show me?

thx

meny

RE: Hello , I wrote a awk script , l

Hi

CODE

ls -ltr --full-time -p | awk '$9 ~ /\//{sub(/\..*/, "", $7); sub(/\//, "", $9); print $6, $7, $9}' 

Feherke.
http://feherke.github.com/

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close