grep/sed query


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep/sed query
# 1  
Old 01-27-2011
grep/sed query

Hi all,
I have one query,in my script,i give one input like sectionname that enclose with[] and that will search in specific file in specific directory.If found ,then it's search next [ or eof ,if found,just decrease line no. and insert lines. like example..
in common.cfg file under config directory.i want to insert some parameter's in last of [CHECKPORT] section and begin of [sometext] section ,sometext means different sectionname.
Code:
[CHECKPORT]
p1
p2
p3
[section2]
p4
p5
p6

I want to insert parameter's below p3.


I did like this....
Code:
N=$(grep -Fwnx "$SECT" $FILE | cut -d ':' -f1)
((N++))
sed -i"{$N}" 'i\' "common.cfg [CHECKPORT] parameter9" config

this code inside loop.

Thanks
surya

---------- Post updated at 06:52 AM ---------- Previous update was at 05:32 AM ----------

Hi all,
let me revise my query,
Actually :- grep -Fwnx "[CHECKPORT]" common.cfg | cut -d ':' -f1 line of code find the line number of checkport section in common.cfg file and
((N++))---->increase the line number
sed -i"{$N}" 'i\' "common.cfg [CHECKPORT] parameter9" inputfile ,insert parameter.

In this code,it's simply add parameter's in begin of checkport section but i need it should insert at end of section.

Thanks
surya

Last edited by Franklin52; 01-28-2011 at 03:28 AM.. Reason: Please use code tags
# 2  
Old 01-27-2011
Why not just sed:
Code:
 
sed '
  s/\[CHECKPORT\].*/&\
new-line-of-data/
 ' common.cfg >common.cfg2

PS: [ is a regex meta character.
# 3  
Old 01-31-2011
HI DGPickett,
This line of code simply substitue the section to new parameter.
I nedd parameter should written at the end of section.

Thnaks
surya
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

File grep quick query

Hi Experts, I need some suggestion on file grep. I am trying to find multiple pattern with the file grep as below grep "2013" trace.log | grep -f pattern.cfg -i > $LOG if ; then mail -s "Exception" "sample@abc.com" < $LOG fi Is it possible to obtain what pattern I got in the... (5 Replies)
Discussion started by: senthil.ak
5 Replies

2. Shell Programming and Scripting

Grep query

Hi, What does this line do grep -E 'ORA-' $LIN_TOP/log/status.log > /dev/null 2>&1 Does this check in status.log and in std out, stderr also.? Thanks (3 Replies)
Discussion started by: nag_sathi
3 Replies

3. Shell Programming and Scripting

grep command query

list ALL file entries with a last modification date of September 20. using grep (1 Reply)
Discussion started by: polineni
1 Replies

4. UNIX for Dummies Questions & Answers

query related to grep

Hi All, The result for 'grep "cert_codes" /develop/sales/appl.srce/*.4gl' command will be saved at aa.txt grep "cert_codes" /develop/sales/appl.srce/*.4gl >aa.txt But I am not sure, whether, all result stored in .txt file in case of multi-line result. Please revert back if... (2 Replies)
Discussion started by: pbankar
2 Replies

5. UNIX Desktop Questions & Answers

ls grep query

Hi please can someone help me with a query? The following command is executed: $ ls abc def hij You execute the command: ls | grep f*. Which files will be displayed and why? thanks (13 Replies)
Discussion started by: tmn0004676
13 Replies

6. Shell Programming and Scripting

Grep query

As part of my never-ending nagios automation project I am need to implement the following run line into a loop; -bash-3.00$ grep ${feed} /usr/local/feed/service/clients/*/bin/* | awk -F/ '{print "To restart: /"$2"/"$3"/"$4"/"$5"/"$6"/"$7"/"$8"/"$9}' Which prints to screen; To restart:... (3 Replies)
Discussion started by: JayC89
3 Replies

7. Shell Programming and Scripting

sed for query

Hi all, I am trying to remove quite a lot of numbers for a file I have which looks something along the lines of; 1,2,3,4,5,6 etc I have a list of numbers I want removing looking like; 10000 10987 16572 etc etc and have been trying to run; for id in `cat list` ; do sed -i -e... (8 Replies)
Discussion started by: JayC89
8 Replies

8. Shell Programming and Scripting

grep command query

Hi I have file like this: Sun Jan 24 03:00:00 2010: *** Weekly Process - get_ens_files.pl START *** Sun Jan 24 03:00:00 2010: *** *** Sun Jan 24 03:00:00 2010: *************************************************** Sun Jan 24 03:00:11 2010: ... (2 Replies)
Discussion started by: koti_rama
2 Replies

9. Shell Programming and Scripting

Query regarding grep

In what cases the following command ignores lines in input file: $ grep -c "^" inputfile (1 Reply)
Discussion started by: amicon007
1 Replies

10. UNIX for Dummies Questions & Answers

query on grep command

Hai Friends Can anyone provide me a grep command to print x to y lines in a file. For example: grep command to display 15th line to 21st Thanks in advance Collins (4 Replies)
Discussion started by: collins
4 Replies
Login or Register to Ask a Question