![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to extract certain part of log file? | superHonda123 | Shell Programming and Scripting | 10 | 05-24-2008 12:56 PM |
| How to extract field from variable more efective | pp56825 | Shell Programming and Scripting | 11 | 01-19-2008 10:34 AM |
| Extract a part of file name | dnat | UNIX for Dummies Questions & Answers | 6 | 12-18-2007 11:19 AM |
| How to extract elements in a field using a number | ahjiefreak | Shell Programming and Scripting | 17 | 12-13-2007 04:13 AM |
| Moving Part of a field to another field using AWK | rjsha1 | Shell Programming and Scripting | 5 | 08-04-2006 05:39 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Extract Part of string from 3rd field $3 using AWK
I'm executing "wc -lc" command in a c shell script to get record count and byte counts and writing them to a file. I get the result with the full pathname of the file. But I do not want the path name to be printed in the output file. I heard that using Awk we can get this but I don't have any knowledge on Awk. Could someone please help me.
Here is what I have in my script #!/usr/bin/csh echo " Records Bytes Filename" >! ${DATDIR}/hlp_NONCE_counts.rtf wc -lc ${DATDIR}/wm_adj_mtg_actvy.dat >> ${DATDIR}/hlp_NONCE_counts.rtf Output of the above 2 commands in the "hlp_NONCE_counts.rtf" file: Records Bytes Filename 2040314 71024727 /export/appl/wodevl/mf/dat/wm_adj_mtg_actvy.dat I do not want this path '/export/appl/wodevl/mf/dat/' to be printed. Instead I just need only the file name like below. Records Bytes Filename 2040314 71024727 wm_adj_mtg_actvy.dat Could someone please help .. Thanks in adv, ST |
|
||||
|
vino,
Thanks for the snippet. But the code doesn't work since I'm using C Shell.. This command doesn't work in c shell "set -- $(wc -lc /etc/passwd)" I tried like below (which isn't efficient since I don't know awk)but the last echo statement isn't working. It gives error as permission denied though the file has read permission: set a=`wc -lc /export/appl/wodevl/mf/dat/wm_adj_mtg_actvy.dat` set xx=`echo $a | awk '{print $1,$2}'` set yy=`echo $a | awk '{print $3}'` set zz=`echo $yy | awk 'BEGIN {FS="/"} {print $7}'` echo $xx | $zz >! out.rtf Can you or anyone suggest me a simple way to do this. Thanks, ST Error Message: wodevl@dwarehouse-udb01lp1:/appl/wodevl 75 % echo $xx | $zz >! out.rtf /export/apps/sched/local/sbin/wm_adj_mtg_actvy.dat: Permission denied. wodevl@dwarehouse-udb01lp1:/appl/wodevl 81 % pwd /export/appl/wodevl/mf/dat -rw-r----- 1 wodevl wodevl 71024727 Oct 8 11:38 wm_adj_mtg_actvy.dat |
|
||||
|
ZS,
THANKS A LOT.... ![]() Excellent piece of code...I was just looking something like that kind of 1 line code...Since I do not know awk, I was just playing by creating variables and concatenate them which is NOT a perfect way..Your code is simple and works.. Thanks again, ST |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|