searching text question


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers searching text question
# 1  
Old 05-28-2005
searching text question

If I am searching through a text file, and it is setup in hierarchical fashion.
ie:

Memory:

256 MB
DDR
Kingston

CPU:

UltraSparc
800 Mhz

can i somehow search for CPU and pull out lines below it as well?
Like grep only pulls that one line, i want that line and 5-10 lines below as well.
And ideas?

Thanks!
Brian
Smilie
# 2  
Old 05-28-2005
Code:
 a=`grep -n "CPU" file1 |cut -d":" -f 1`
 ((b=a+5))
  sed -n "$a,$b p" file1

# 3  
Old 05-28-2005
nawk -v search='CPU:' -f bg.awk bgFile

here's bg.awk:
Code:
BEGIN {
  RS=FS=""
}
$1 == search { getline; print ; next}

# 4  
Old 05-28-2005
Code:
#!/usr/bin/sh
for line in 'CPU:' 'Memory:'
do
lineno=`grep -n $line test.tmp|awk -F":" '{print $1}'`
lineno1=`expr $lineno + 5`
sed -n "${lineno},${lineno1}p" test.tmp
done

# 5  
Old 05-29-2005
thanks~

Thanks guys for your help, i appreciate it very much!

Brian
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert Text after searching via grep

Hi Team, I have a file with the following patterns: ==> xyz_Server_Started_with_Errors <== errors. ==> abc_Server_Started_with_Errors <== errors ==> reds_Server_Started_with_Errors <== errorss I want them in this format: (5 Replies)
Discussion started by: ankur328
5 Replies

2. Shell Programming and Scripting

Need help searching through a text file.

I'm trying to get one specific number out of a text file, in order to use as part of an algorithm in a shell script. It will always come after a specific string and that string won't appear anywhere else in the file. So I'm trying to search through the file for that one string, then grab the... (2 Replies)
Discussion started by: mikedigornio
2 Replies

3. Shell Programming and Scripting

searching a file with a specified text without using conventional file searching commands

without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies

4. Shell Programming and Scripting

Need help with searching and copying in a text file

Hi, I need help searching through a large text file. I need to find a certain string within the text, and copy each line until another string appears. The file looks like this: >scf15164843 ATTAAAGGNNNGGAATTTCCCCAA ATTACCGGCTTTAAANNNTTACCC >scf15154847 CCGGGNNNTTTAAACCCGNGNGCC... (2 Replies)
Discussion started by: repiv
2 Replies

5. Shell Programming and Scripting

Question about partial searching

Hi there! New user to UNIX scripting. Had a question I was stuck on. I've been trying to make a script(for a larger project) that would search a file(lets say playerlist). the file is already formatted into columns so it may look like First name(1-10) Last Name(11-20) address (21-30) ... (23 Replies)
Discussion started by: Sagramor
23 Replies

6. Shell Programming and Scripting

searching a text string for n'th :

hello, i'm a novice on bsh scripting so thanks for any help here basically i have a shell var $x that looks like this > echo $x nabc1234:!:73394:17155:Gary Mason:/home/garym:/bin/ksh and i'm trying to keep the first 8 characters and the text from the 4th : to the 5th : i've been trying... (9 Replies)
Discussion started by: sasglm
9 Replies

7. UNIX for Advanced & Expert Users

Searching filenames containing certain text???

Suppose there are multiple files containing certain text "abc". How to print the name of all such files with a single command from unix prompt? Thanks in advance (6 Replies)
Discussion started by: skyineyes
6 Replies

8. Shell Programming and Scripting

searching each file in a directory for text

what command can i use to search the files in a directory for a text. the output would list the files containing the text. ive tried this but it is not exactly what im looking to do: find . -name "*.xml" -exec agrep searchstring {} \; (2 Replies)
Discussion started by: jim majors
2 Replies

9. Linux

Searching for text in files

Is there anyway that I can run a search of all files for matching strings(or even just a subset of all files) from the command line on Linux system? e.g check all files in the current directory that have 'cisco' in them........ find doesnt seem to be right as it only(well it appears to me... (2 Replies)
Discussion started by: GandalfWhite
2 Replies

10. Shell Programming and Scripting

Help with searching a text file

Hello all! I've been working for days on this and it is really bugging me!! Here's my dilemma: Say I have a very large text file which contains fields delimited my a ':' which logs various records. Each record is separated by a newline character, therefore I can search for lines with... (6 Replies)
Discussion started by: thekid2
6 Replies
Login or Register to Ask a Question