|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | 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. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
Need help in inserting a value.........
Hello,
I'm having a files with variable no of lines. An example for this file is as follows ~xxx STRT 0.0000000000 : STOP : ~xxxxx 0.000000 557.109552 -557.109552 1511.482910 -954.373377 954.373377 in the STOP line below the 0.00000000000 I need the first coloumn of the last line ie in this case 1511.482910. In each file the value will be changing. I'm having more than 500 of such files. I believe a shell script or awk can handle this. Please help me. |
| Sponsored Links |
|
|
|
|||
|
Quote:
awk '{field = $1 }; END {print field}' filename but my need is to print this value next to STOP. |
|
|||
|
hope below one can help, it suppose all your files are named with .txt suffix. Code:
for i in `ls *.txt`
do
val=`cat $i | tail -1 | awk '{print $1}'`
nawk -v val="$val" '{
if(index($0,"STOP")!=0)
print $0" "val
else
print
}' $i
done |
|
|||
|
It would have been easier for willing repliers if you had provided us with line numbers so that it gets conspicuous what characters still belong to the same line. This is rather ambiguous Quote:
if it really is in the same STOP line, it should be as simple as e.g. Code:
$ awk -F' : ' '$1~/^STOP/{print$2}' file_to_parseBut I guess this wasn't meant? If it were on the other hand on a different line following the STOP marker (can't fathom what ~xxxxx shall denote) then you would have to parse this line. Sticking with the assumed line count, and assuming GNU grep was available you could then maybe do something like Code:
$ grep -A3 ^STOP file_to_parse|tail -1|cut -d\ -f1 But I don't want to fall prey to era's useless use content here, why this could better be accomplished in a single awk statement after you have told us how the line counting goes. |
| Sponsored Links |
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Inserting a new line | ssmallya | Shell Programming and Scripting | 1 | 07-18-2008 04:21 AM |
| inserting line?? | anj | UNIX for Dummies Questions & Answers | 7 | 11-03-2007 12:18 PM |
| Inserting 1st arg into middle | boris | Shell Programming and Scripting | 2 | 04-13-2007 03:41 PM |
| Inserting a carriage rtn in a sed cmd | sirtrancealot | Shell Programming and Scripting | 6 | 07-14-2006 06:08 AM |
| Inserting a space | dbrundrett | Shell Programming and Scripting | 3 | 02-27-2004 12:44 PM |