Question to gurus about sed.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question to gurus about sed.
# 8  
Old 07-17-2013
Thanks, but what you can advise for me in my case.
Stas.

---------- Post updated at 01:53 AM ---------- Previous update was at 01:34 AM ----------

Hi rajamadhavan.,
Perl commands not help me, sorry.
Thanks Stas.
# 9  
Old 07-17-2013
try something like this.. Here i asuumed DATAFILE as pattern after your last , removal

Code:
 
sed -n '/^DATAFILE/{x;s/,//;x;};1h;1!{x;p;};${x;p;}' filename

# 10  
Old 07-17-2013
Please edit your code and wrap it in [code] tags! (See the top of the WIKI editor.)
Based on your first sample (corrected by Scott), here is something that works with the indention:
Code:
awk '{i=index($0,")")} i>0 {s=$0; getline; j=index($0,$1); if (j<i) sub(", *$","",s); print s} {print}' file

The sub() strips the comma at the end if the next line has got less indention.
# 11  
Old 07-17-2013
Thanks vidyadhar85.,
You sed command is work perfect, can you only explain me what some of brackets are mean ......
Code:
sed -n '/^DATAFILE/{x;s/,//;x;};1h;1!{x;p;};${x;p;}'

Thanks Stas.

Last edited by Scott; 07-17-2013 at 09:30 AM.. Reason: Code tags
# 12  
Old 07-17-2013
Quote:
Originally Posted by beckss
Thanks vidyadhar85.,
You sed command is work perfect, can you only explain me what some of brackets are mean ......


sed -n '/^DATAFILE/{x;s/,//;x;};1h;1!{x;p;};${x;p;}'


Thanks Stas.
Glad it worked out for you Smilie

here on finding DATAFILE ^ indicates starting from.. exchange the pattern and hold space then replace the , and again do the same
1h indicates copy of pattern space to hold space so that when pattern found we have previous line in hold space.
1!{x;p;};${x;p;} these are to avoid blank lines
# 13  
Old 07-17-2013
Once you have understood this, you can simplify to
Code:
sed '/^DATAFILE/{x;s/, *$//;x;};1h;1d;x;$p;$x'

Still it only works with GNU sed.
The Unix sed seem to have a problem with the { }. (That's why I prefer awk.)
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question to gurus with expect

Hi., I need to ask question for expect script. I have prompt like # and very long script (orachk). I added to expect script line set prompt "(%|#|\\\$) $" and insert into it also piece of code ---- expect { timeout { puts "Running..." exp_continue } ... (0 Replies)
Discussion started by: beckss
0 Replies

2. UNIX for Dummies Questions & Answers

Calling all the awk gurus out there.

Hi all, I just signed up to the forums, although, I have lurked on here for awhile. Anyways, my issue is I am trying to get awk to spit out something I can use without having to spend hours in excel hell haha. So, I used sed to replace the spaces with semicolons and redirected that to a file. ... (6 Replies)
Discussion started by: savigabi
6 Replies

3. Shell Programming and Scripting

calling mysql gurus : need help with my view

hi there I have a view which is working fine, but i have been told that i need to make sure the resulting output excludes all rows with nic_status equal to the string "removed". Does anybody know in which part of the code below i would place the conditional ... WHERE nic_status !=... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

4. Shell Programming and Scripting

Bash script questions for gurus

guys, I need a steer in the right direction for this issue. it would be great if anyone of you can help me out. i have a textfile where i want to swap the lines based on the user input. The textfile is looks like the #file 1 name TB #file 1 ID 1000 # #file for ID1 system1... (3 Replies)
Discussion started by: mayi
3 Replies

5. Shell Programming and Scripting

VI Editor - question for unix gurus !!

I have created a dummy file -demo.txt On my machine-A (oslevel-5300-08) I can display the file content in HEX format through VI editor using :%!xxd but on other machine-B (oslevel - 5300-06) , I get error as "sh: xxd: not found." machine-A: $ cat demo.txt Hello World ! I can display... (7 Replies)
Discussion started by: Rahulpict
7 Replies

6. Shell Programming and Scripting

Unix/Linux gurus...here is Q 4u

Suppose I have two files 1.txt and 2.txt. My aim is to find (Total execution time/Number of executions) then sort the result as in decreasing order. Can anyone provide me any shell/perl/awk script or a Command to do that in faster way ? 1.txt : =============================== Number of... (4 Replies)
Discussion started by: Rahulpict
4 Replies

7. Shell Programming and Scripting

Hey Perl Gurus

Hey guys im trying to get this if statement to work and i dont know whats wrong. can anybody help? if($author=~/\A+\Z/i)&&(length($author!=0)) { print " $author validation correct" } elsif($author!=~/\A+\Z/i)&&(length($author=0)) { $author='BLANK'; } else { ... (1 Reply)
Discussion started by: neil1983
1 Replies

8. Shell Programming and Scripting

SED GURUS - Help!

I wish to substituite a string on each line but ONLY if it appears within double-quotes: this_string="abc#def#geh" # Comment here I wish to change the "#" characters within the double quoted string to "_": this_string="abc_def_geh" # Comment here ... but as you see, the "comment" hash... (2 Replies)
Discussion started by: Simerian
2 Replies

9. UNIX for Advanced & Expert Users

Any RF unix gurus out there?

I am having a problem here. We are having several problems in regards to hung process's on unix (HPUX box), caused by my RF equipment (Mobile data capture units). these contact the host via a simply telnet session and locks the system? Is it a timeout problem as the timeout is disabled on the host. (5 Replies)
Discussion started by: Subrosa
5 Replies
Login or Register to Ask a Question