![]() |
|
|
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 |
| Script for reading filelist and preparing param file. | thebeginer | UNIX for Dummies Questions & Answers | 2 | 10-05-2007 05:19 PM |
| chmod - pass a filelist as a parameter? | alangibson | UNIX for Dummies Questions & Answers | 2 | 04-11-2007 09:44 AM |
| how to get nth file filelist | balireddy_77 | Shell Programming and Scripting | 1 | 11-20-2006 02:17 AM |
| Help with for loop within two scripts | chiru_h | Shell Programming and Scripting | 3 | 09-08-2006 11:38 AM |
| How to combine "find" command in for each loop (tcsh) | umen | Shell Programming and Scripting | 3 | 08-22-2005 05:07 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
i want to combine two awk scripts which is having same loop and filelist
hi,
to all give me some idea below scripts file=`cat filelist` for filename in $file do awk '{ if ($0 ~ /system/ && flag == 0) { flag=1; print $0; } else if ($0 ~ /system/ && flag == 1) { printf("%s SYSLAY %s %s %s\n",$1,$3, $4, $5); } else print $0; }' $filename > temp.txt mv temp.txt $filename done for this script1 : i have to add a new line which contain syslay for the filelist containing system. and that system occurs two times so after the second occurence i have to add new line . i have done like this if there is any other solution of this please send the solution. files=`cat filelist` for filename in $files do awk '{ if ( $0 ~ /narayana / && flag == 0 ) { flag=1 print $0; } else if ( $0 ~ /narayana/ && flag == 1 ) { printf("%s %s /narayana/mde\n",$1,$2); } else print $0; }' $filename > temp.txt mv temp.txt $filename.tmp done script2: i have to add '/mde' for narayana as narayana/mde for the files in the filelist . And for this also for the second occurence of the line containing narayana only should be changed . i have to merge these two scripts as one so kindly help in this matter urgently example; this is not a typical example narayana solution is not verified this section is to be changed narayana sos ana s plaea the above is example of the file and it should be modiefied as this is not a typical example narayana/mde solution is not verified this section is to be changed narayana/mde sos ana s plaea with regards narayana |
|
|||||
|
The following version of the script modifies lines :
Code:
file=`cat filelist`
for filename in $file
do
awk '
BEGIN {
system_occ = 1;
narayana_occ = 3;
}
/system/ {
++flag_system;
if (flag_system >= system_occ) {
printf("%s SYSLAY %s %s %s\n",$1,$3, $4, $5);
next;
}
}
/narayana/ {
++flag_narayana;
if (flag_narayana >= narayana_occ) {
printf("%s %s /narayana/mde\n",$1,$2);
next;
}
}
1
' $filename > temp.txt
mv temp.txt $filename
done
|
|
||||
|
again i have to add another script for this
for the above script which u have given the solution for the solution i have to add another script also
for the below file i have remove a comment after the line narayana this is not a typical example #narayana #solution is not verified #this section is to be changed #narayanae sos ana s plaea this is not a typical example narayana solution is not verified this section is to be changed narayana sos ana s plaea please kindly give the solution with regards narayana |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|