Don,
>Are you saying that you:
- yes, this is corrrect .
1. want to find a line that contains lan5:5 ,
2. find a digit string between [ and ] on that line, and then
3. remove every line in the file that contains that digit string between [ and ] ?
Thank you..
Reveri.
OK. Doing exactly what you're requesting, I have an example that uses sed and ex. If you only need to delete lines that contain the digit string between [ and ] after finding lan5:5, I also have an awk example that does that. The following script includes both of these examples. Hopefully, one or both of these will do what you want:
I use the Korn shell, but this will also work with bash or any other POSIX conforming shell. If you are using a Solaris/SunOS system, use /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk instead of awk.
If you save the above script in a file named tester, make it executable by running the command:
and then run the command:
(assuming that the input file you showed us in message #1 in this thread is stored in a file named file and the expected output shown in that message is stored in a file named expected), the output produced will be something like:
The number after "backup" in the output shown above in orange, is the process ID of the shell running this script.
If you then copy the backup file created by this script back to your input file and run it again with something like:
it will display error messages indicating that it couldn't find lan5:x, show the updated input file produced by sed and ex, show the diffs between what awk script produced and what you wanted, and show the temp file created by awk.
If everything works as expected, remove the backup file after you have verified that your input file has been updated to contain what you wanted.
If the awk script fails, it may also leave around a file named _tmpdigits where digits is also the process ID of the shell running this script. If it was an actual awk error (instead of not finding the given pattern in your input file), this temp file may help you debug what went wrong.
I hope the comments in the script explain what is going on, but if part of it doesn't make sense, feel free to ask for an explanation of the parts you don't understand.
The index search is similar:
Narrative: sed no auto print mode find the key line and cut out the digits inside the square braces and print them to the for loop, which for each index found, removes all the lines indexed by that number in the file. Normally I use a while read, but since we are changing the file we are getting indexes from, I get all indexes before doing index deletes.
Hi,
I have a file. File contains are as follows :
Feb 19, 2012 5:05:00 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Feb 19, 2012 5:05:00 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 771 ms
Feb 20, 2012... (3 Replies)
Hi, I have a file input.txt. cat input.txt output is as follows : Code: "0001"~"name"~"bb"~"20.25"~""~""~"0002"~"name" "dd"~"35.50"~"" ~""~"0003"~"name"~"aa"~"21.3 5"~""~""~ I want the output looking like: cat output.txt Code: "0001"~"name"~"bb"~"20.25"~""~""~... (6 Replies)
Hi All, I have a file. This file contain huge amount of data. I want to modify this file. I want enter new line when count of "~ character is 79. Please find below the code : cat file_name | tr -d '\n' | sed... (6 Replies)
Hi All,
I have a file disk_space.log.
cat disk_space.log
94% /
32% /boot
38% /mnt/data
100% /media/CDROM
I want the output, like
cat disk_space.log
94% /
100% /media/CDROM
That means print the line those are grater-than 90%. And rest of the line is remove from file.
I have a... (2 Replies)
Hi,
I have a file abcd.txt.
cat abcd.txt
output is as follows :
"aa"~"bb"~"001"~""~""~"cc"
"dd"~"005"~""
~""~"kk"~"aa"~"00
8"~""~""~
I want the output looking like:
cat abcd.txt
"aa"~"bb"~"001"~""~""~
"cc""dd"~"005"~""~""~
"kk"~"aa"~"008"~""~""~
I have a script. (4 Replies)
Hi,
I have a file test.txt . The contain of the file is as below :
365798~SAPUS~PR5~0000799005~ADM CHARG MEDCAL INS~~~~~~~~~~~~~~~~~~~~~~~~SLAC480
I want to modify this file. And file contain loking like
"365798"~"SAPUS"~"PR5"~"0000799005"~"ADM CHARG MEDCAL... (6 Replies)
Dear all,
I 'd like to create a new txt file using the old file. For example, in old file, if count=2 then in new file, repeat that row twice, with the only difference is: on the first row, 'start' column contains the 1st apart of the 'start' in the old file; while in the 2nd row, the 'start'... (7 Replies)
Can anyone please suggest an alternate command for "stat" . I am trying this on Solaris 5.9 , but the command doesn't exist.
Basically i need to see one particalar file modification history. Any help is appreciated. (4 Replies)
Hi
I am accessing a file on nfs mounted device, after completing using of the file, i am tring to restore the access time and modification times of the file.
So i got the previous modified time of the file using stat() function and trying to set the date and time for the file, To set these... (6 Replies)