sed Unexpected results, missing first search item


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed Unexpected results, missing first search item
# 1  
Old 08-07-2013
sed Unexpected results, missing first search item

I created 3 files with the identical data as follows

Code:
dial-peer voice 9999 pots
 trunkgroup CO
 list outgoing Local
 translation-profile outgoing LOCAL-7-DIGITS-NO-PREPEND-97
 preference 2
 shutdown
 destination-pattern 9[2-9]......$
 forward-digits 7


dial-peer voice 10000 pots
 trunkgroup CO
 list outgoing Local
 translation-profile outgoing LOCAL-7-DIGITS-NO-PREPEND-97
 preference 2
 shutdown
 destination-pattern 9[2-9]......$
 forward-digits 7


dial-peer voice 11111 pots
 trunkgroup CO
 list outgoing Local
 translation-profile outgoing LOCAL-7-DIGITS-NO-PREPEND-97
 preference 2
 shutdown
 destination-pattern 9[2-9]......$
 forward-digits 7


I named them rx, rx1, rx2
I used vi set list to ensure the files were in nix format.

I ran the following script(s)

Code:
#!/bin/ksh
for x in `ls rx*`
#ls -l rx* | awk '{print $9} | while read x
do
sed -n -e '/^dial.*10000/p' -e '/ shutdown/{p;q}' $x
done


the exact output

Code:
backupdir> xx
 shutdown
 shutdown
 shutdown
backupdir>

I ran dos2unix on all three files just to be sure they are in nix format.
# 2  
Old 08-07-2013
You will need a semi-colon after the q

Code:
... {p;q;} ...

Code:
#!/bin/ksh
for x in rx*
do
  sed -n -e '/^dial.*10000/p' -e '/ shutdown/{p;q}' $x
done

 shutdown
dial-peer voice 10000 pots
 shutdown
 shutdown


Last edited by Scott; 08-07-2013 at 12:46 PM.. Reason: Wrong output
# 3  
Old 08-07-2013
Code:
#!/bin/ksh
for x in `ls rx*`
do
sed -n -e "/^dial.*10000/p" -e "/ shutdown/{p;q;}" $x
done

output

Code:
backupdir> xx
 shutdown
 shutdown
 shutdown
backupdir>

what Im after
Code:
dial-peer voice 10000 pots
 shutdown

# 4  
Old 08-07-2013
if you just wanted the line that has 10000 on them, sed works well ...
Code:
[root@centosgeek ~]# sed -n "/10000/p" testfile3 | sed -e "s/$/\n shutdown/"
dial-peer voice 10000 pots
 shutdown
[root@centosgeek ~]#

if you wanted to grab all the dial-peer lines at once, use awk instead ...
Code:
[root@centosgeek ~]# awk '/dial-peer/ || /shutdown/ {print}' testfile3
dial-peer voice 9999 pots
 shutdown
dial-peer voice 10000 pots
 shutdown
dial-peer voice 11111 pots
 shutdown
[root@centosgeek ~]#

# 5  
Old 08-12-2013
Code:
[root@centosgeek ~]# sed -n "/10000/p" testfile3 | sed -e "s/$/\n shutdown/"


Doesn this say replace then end of line with "\n shutdown" ??
# 6  
Old 08-12-2013
Try this
Code:
sed -n  '/^dial.*10000/,$ {/^dial/p; / shutdown/ {p;q}}' file
dial-peer voice 10000 pots
 shutdown

# 7  
Old 08-12-2013
The results :

This one has got me scratching my head .. for sure ....


Code:
dial-peer voice 595176 pots
dial-peer voice 66 voip
dial-peer voice 65176 voip
dial-peer voice 65 voip
dial-peer voice 10000 pots
dial-peer voice 6176 voip
dial-peer voice 10000 pots
dial-peer voice 69 voip
dial-peer voice 69176 voip
dial-peer voice 69 voip
dial-peer voice 698 voip
dial-peer voice 8176 pots
dial-peer voice 81176 pots
dial-peer voice 8176 pots
dial-peer voice 4176 pots
dial-peer voice 41695 voip
dial-peer voice 999999 voip
 shutdown

dial-peer voice 595176 pots
dial-peer voice 66 voip
dial-peer voice 65176 voip
dial-peer voice 65 voip
dial-peer voice 10000 pots
dial-peer voice 6176 voip
dial-peer voice 10000 pots
dial-peer voice 69 voip
dial-peer voice 69176 voip
dial-peer voice 69 voip
dial-peer voice 698 voip
dial-peer voice 694 voip
dial-peer voice 695 voip
dial-peer voice 8176 pots
dial-peer voice 81176 pots
dial-peer voice 8176 pots
dial-peer voice 4176 pots
dial-peer voice 41695 voip
dial-peer voice 999999 voip
 shutdown

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Large search replace using sed results in memory problem.

I have one big file of size 9GB (big_file.txt). This big file has sentences and paragraphs like any usual English document. I have another file consisting of replacement strings for sed to use. The file name is replace.sed and each entry in one line looks like this: s/\<shout\>/shout/g s/\<b is... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

2. Shell Programming and Scripting

Seeing unexpected results when i run through cronjob

Hi I'm having hard time here with below script. If i run script manually i see expected results but, if i keep this script in cron job i'm getting unexpected results. Unexpected results means even though condition is true,cronjob returning output of else condition. This script and cronjob... (2 Replies)
Discussion started by: buzzme
2 Replies

3. Shell Programming and Scripting

Comm giving unexpected results

Hi I am comparing two files with comm -13 < (sort acc11.txt) < (sort acc12.txt) > output.txt purpose: Get non matching records which are in acc12 but not in acc11... TI am getting WRONG output. Is there any constraints with record length with comm? The above files are the two consective ... (2 Replies)
Discussion started by: vedanta
2 Replies

4. Shell Programming and Scripting

Unexpected results with lists in GNU sed

I have been living with this problem with GNU sed v4.1.4 for a long time, but now I really need to figure it out. When using a list in either an address or a search, the expression is matching lower and upper-case letters. works as it should. For example, if I run sed -nr "// p"... (7 Replies)
Discussion started by: nctrader
7 Replies

5. Shell Programming and Scripting

Can ctag and cscope support recording search results and displaying the history results ?

Hello , When using vim, can ctag and cscope support recording search results and displaying the history results ? Once I jump to one tag, I can use :tnext to jump to next tag, but how can I display the preview search result? (0 Replies)
Discussion started by: 915086731
0 Replies

6. UNIX for Dummies Questions & Answers

Find command gave unexpected results

Hi, I recently executed a find command that caused unexpected permission changes and we had to do a full system restore. Can someone please explain what this command would do? find /staging/admin/scr * -exec chmod 755 '{}' + It caused file permissions inside / to be modified strangely. ... (1 Reply)
Discussion started by: poornima
1 Replies

7. Shell Programming and Scripting

Unexpected results when triggered from cron

Following script gives different results when triggered from Cron compared to when triggered from command line. It is not able to assign values to some variables when triggered from cron. Can any one help? Its a very simple script Script - #! /bin/ksh sFile=$1 sEnv=$2 sWaitFile=$3... (1 Reply)
Discussion started by: sumeet
1 Replies

8. Shell Programming and Scripting

Unexpected Results (at least I did not expect them)

I have two sripts running in bash. The first one uncompresses log files and moves them to a working directory using uncompress -c and > output to new directory. It then creates one control record to assure our search returns a record. It then calls or executes the second script, which is a grep for... (6 Replies)
Discussion started by: altamaha
6 Replies

9. UNIX for Dummies Questions & Answers

Unexpected Results

Hello, When I run this script, here's what I get: Searching ... found 1111 2222 3333 ..... 7777 ..... 8888 9999 in 95_test Search completed. I expected only to see what number was found in the file, not including the ones not found. Thanks for your help! #!/bin/sh (1 Reply)
Discussion started by: SSims
1 Replies
Login or Register to Ask a Question