Computing.Net > Forums > Unix > finding a string from text

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.

finding a string from text

Reply to Message Icon

Name: krsatya
Date: April 29, 2007 at 08:58:13 Pacific
OS: hpux
CPU/Ram: 4gb
Product: HP
Comment:

there is a txt doc that i have. i have to find a string which is in middle of the line and if it finds that string then my script sshould output the whole line and also 4 more lines which come after 5 or 6 lines..i m not able to do this using awk..
here is a sample file
<BasketTab state="INSERTED">MyBasketsTab</BasketTab>
<Locale state="INSERTED">en_US</Locale>
<UserKey state="INSERTED">323213</UserKey>
<CountryLookupType state="INSERTED">Country</CountryLookupType>
<BasketLookupType state="INSERTED">BasketType</BasketLookupType>
<SortOrder state="INSERTED">ASC</SortOrder>
<OACountries state="INSERTED">170,1050</OACountries>
<SearchCountry state="INSERTED">0</SearchCountry>
<SearchBasketName state="INSERTED">NULL</SearchBasketName>
<SearchOriginatorName state="INSERTED">NULL</SearchOriginatorName>

i want to check if line contains "mybasketstab" or not and if yes , i want that line and last 2 lines to be outputted to a diff txt file



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: April 29, 2007 at 23:58:11 Pacific
Reply:

[code]
awk 'BEGIN{}
/MyBasketsTab/ { print }
{ temp2 = temp1; temp1 = $0 }
END {
print temp2
print temp1
} ' "file"

[/code]


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: finding a string from text

Find a string; print next line www.computing.net/answers/unix/find-a-string-print-next-line/7661.html

sh Find the length of a string www.computing.net/answers/unix/sh-find-the-length-of-a-string/7414.html

Replace a string in Script www.computing.net/answers/unix/replace-a-string-in-script/7047.html