Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Unix Commad
Name: Janet Date: December 27, 2002 at 21:45:57 Pacific OS: Sun Solaris CPU/Ram: P4/2GB
Comment:
Hi Could any tell me how to retrieve a result (oranges) between two lines of a file
eg
Apples (first line) Oranges (second line) grapes (third line)
I want to be able to get the second line information in this case oranges
Name: Jimbo Date: December 28, 2002 at 04:13:41 Pacific
Reply:
sed -n '2p' your_file
will give you the second line.
-jim
0
Response Number 2
Name: David Perry Date: December 28, 2002 at 06:32:27 Pacific
Reply:
head -2 filename | tail -1
0
Response Number 3
Name: James Boothe Date: December 28, 2002 at 07:51:58 Pacific
Reply:
Maybe Janet is wanting the second line shown, where those set of lines could occur anywhere in the file. If that is the case, it becomes quite a bit more difficult.
The following script would do it, and to keep this web page from losing my indentation, I use underscores, so you would have to change those underscores back to spaces.
#!/bin/sh awk '{\ if ($1=="grapes"&&holdflag==1) ___{print hold;exit} if (apples==1) ___{hold=$0;holdflag=1} else ___holdflag=0 if ($1=="Apples") ___apples=1 else ___apples=0 }' filename exit 0
Summary: Dear All, I have a requirement that we need to identify frequently used programs in a directory. Basically we need to identify the date of last execution of a program in unix directory. Could anyon...
Summary: Hi friends, I am executing a SQL through UNIX. I receive a date from SQL and store it in a variable in unix. The date is in (13-AUG-2009) format. But i need this to be in YYYYMMDD(20090813). Kindly...