10-13-2008
Hi Summer_Cherry,
Million thanks for giving me the piece of code which will comment starting from second occurance of matched pattern from the starting of line.
intelsol2>cat 1.txt
0152364|134444|10.20.30.40|015236433
0233654|122555|10.20.30.50|023365433
intelsol2>cat 2.txt
0152364|134444|10.20.30.40|015236433
0233654|122555|10.20.30.50|023365433
0789456|332211|10.20.30.40|078945633
1234567|225522|10.20.30.50|123456733
0321654|999999|10.20.30.40|032165433
0456123|777899|10.20.30.40|045612333
intelsol2>
nawk 'BEGIN{FS="|"}
{
if (NR==FNR)
a[$3]=0
else
{
a[$3]++
if (a[$3]>=2)
print "#"$0
else
print $0
}
}' 1.txt 2.txt >3.txt
intelsol2>cat 3.txt
0152364|134444|10.20.30.40|015236433
0233654|122555|10.20.30.50|023365433
#0789456|332211|10.20.30.40|078945633
#1234567|225522|10.20.30.50|123456733
#0321654|999999|10.20.30.40|032165433
#0456123|777899|10.20.30.40|045612333
intelsol2>
Also thanks a lot for unix forum guys "you ppl rock!!!"
FYI, i was trying to search for this code since all the weekend and went through sed manual "http://www.grymoire.com/Unix/Sed.html" sub topic (/1, /2, etc. Specifying which occurrence) however was unlucky in trying all the trial and error method.
Also Summer could you please explain me the code you have written so that i can understand it in a better way.
Again thanks a lot and you can close this thread.
Thanks
-imas
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi,
I am new to this forum and i would like to get help in this issue.
I have a file 1.txt as shown:
apple
banana
orange
apple
grapes
banana
orange
grapes
orange
....
Now i would like to search for pattern say apple or orange and then put a # at the beginning of the pattern... (2 Replies)
Discussion started by: imas
2 Replies
2. UNIX for Dummies Questions & Answers
Hi,
I think you ppl did not get my question correctly, let me explain
I have 1.txt with following entries as shown:
0152364|134444|10.20.30.40|015236433
0233654|122555|10.20.30.50|023365433
**
**
**
In file 2.txt I have the following entries as shown:
... (1 Reply)
Discussion started by: imas
1 Replies
3. Shell Programming and Scripting
trying to use sed in finding a matching pattern in a file then deleting
the next line only .. pattern --> <ad-content>
I tried this but it results are not what I wish
sed '/<ad-content>/{N;d;}' akv.xml > akv5.xml
ex,
<Celebrant2First>Mickey</Celebrant2First>
<ad-content>
Minnie... (2 Replies)
Discussion started by: aveitas
2 Replies
4. UNIX for Dummies Questions & Answers
I have a file that will sometimes contain a pattern. The pattern is this:
W/D FRM CHK 00
I want to find any lines with this pattern, delete those lines, and also delete the line above and the line below. (1 Reply)
Discussion started by: nickg
1 Replies
5. Shell Programming and Scripting
I have a file that will sometimes contain a pattern. The pattern is this:
FRM CHK 0000
I want to find any lines with this pattern, delete those lines, and also delete the line above and the line below. (4 Replies)
Discussion started by: nickg
4 Replies
6. Shell Programming and Scripting
i have a file sample.txt containing
i want to delete lines starting with 123 neglecting spaces and tabs.
but not lines containing 123. i.e.
i want files sample.txt as
help me
thanxx (4 Replies)
Discussion started by: yashwantkumar
4 Replies
7. Shell Programming and Scripting
Hi, just tried some script, awk, sed for the last 2 hours and now need help.
Let's say I have a huge file of 800,000 lines like this :
It's a tedious job to look through it, I'd like to remove those useless lines in it as there's a few thousands :
Or to be even more precise :
if line1 =... (6 Replies)
Discussion started by: Zurd
6 Replies
8. Shell Programming and Scripting
'Hi
I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match.
Which option is to be used to exclude the line containing the pattern?
sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies
9. UNIX for Dummies Questions & Answers
Hi all!
Thanks for taking the time to view this!
I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern.
Example:
Drink a soda
Eat a banana
Eat multiple bananas
Drink an apple juice
Eat an apple
Eat multiple apples
I... (8 Replies)
Discussion started by: demmel
8 Replies
10. UNIX for Beginners Questions & Answers
I have a file with a list of references towards the end and want to apply a grep for some string.
text ....
@unnumbered References
@sp 1
@paragraphindent 0
2017. @strong{Chalenski, D.A.}; Wang, K.; Tatanova, Maria; Lopez,
Jorge L.; Hatchell, P.; Dutta, P.; @strong{Small airgun... (1 Reply)
Discussion started by: kristinu
1 Replies
LEARN ABOUT REDHAT
mac2unix
dos2unix(1) General Commands Manual dos2unix(1)
NAME
dos2unix - DOS/MAC to UNIX text file format converter
SYNOPSYS
dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...]
Options:
[-hkqV] [--help] [--keepdate] [--quiet] [--version]
DESCRIPTION
This manual page documents dos2unix, the program that converts plain text files in DOS/MAC format to UNIX format.
OPTIONS
The following options are available:
-h --help
Print online help.
-k --keepdate
Keep the date stamp of output file same as input file.
-q --quiet
Quiet mode. Suppress all warning and messages.
-V --version
Prints version information.
-c --convmode convmode
Sets conversion mode. Simulates dos2unix under SunOS.
-o --oldfile file ...
Old file mode. Convert the file and write output to it. The program default to run in this mode. Wildcard names may be used.
-n --newfile infile outfile ...
New file mode. Convert the infile and write output to outfile. File names must be given in pairs and wildcard names should NOT be
used or you WILL lost your files.
EXAMPLES
Get input from stdin and write output to stdout.
dos2unix
Convert and replace a.txt. Convert and replace b.txt.
dos2unix a.txt b.txt
dos2unix -o a.txt b.txt
Convert and replace a.txt in ASCII conversion mode. Convert and replace b.txt in ISO conversion mode. Convert c.txt from Mac to Unix
ascii format.
dos2unix a.txt -c iso b.txt
dos2unix -c ascii a.txt -c iso b.txt
dos2unix -c mac a.txt b.txt
Convert and replace a.txt while keeping original date stamp.
dos2unix -k a.txt
dos2unix -k -o a.txt
Convert a.txt and write to e.txt.
dos2unix -n a.txt e.txt
Convert a.txt and write to e.txt, keep date stamp of e.txt same as a.txt.
dos2unix -k -n a.txt e.txt
Convert and replace a.txt. Convert b.txt and write to e.txt.
dos2unix a.txt -n b.txt e.txt
dos2unix -o a.txt -n b.txt e.txt
Convert c.txt and write to e.txt. Convert and replace a.txt. Convert and replace b.txt. Convert d.txt and write to f.txt.
dos2unix -n c.txt e.txt -o a.txt b.txt -n d.txt f.txt
DIAGNOSTICS
BUGS
The program does not work properly under MSDOS in stdio processing mode. If you know why is that so, please tell me.
AUTHORS
Benjamin Lin - <blin@socs.uts.edu.au>
Bernd Johannes Wuebben (mac2unix mode) <wuebben@kde.org>
MISCELLANY
Tested environment:
Linux 1.2.0 with GNU C 2.5.8
SunOS 4.1.3 with GNU C 2.6.3
MS-DOS 6.20 with Borland C++ 4.02
Suggestions and bug reports are welcome.
SEE ALSO
unix2dos(1) mac2unix(1)
1995.03.31 dos2unix v3.0 dos2unix(1)