Double Spacing complex sed pipeline


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Double Spacing complex sed pipeline
# 1  
Old 12-05-2008
Double Spacing complex sed pipeline

my script:
Code:
 
FILE="$1"
echo "You Entered $FILE"
if [ -f $FILE ]; then
tmp=$(cat $FILE | sed '/./!d' | sed -n '/regex/,/regex/{/regex/d;p}'| sed -n '/---/,+2!p' | sed -n '/#/!p' | sed 's/^[\
]*//' | sed -e\
s/[^:]*:// | sed -n '/==> /!p' | sed -n '/--> /!p' | sed -n '/regex/,+1!p' | sed -n '/======/!p' | sed -n '/regex/!p' | sed -n '\
/regex/!p' | sed -n '/regex /!p')
fi
MyVar=$(echo $tmp > my.txt)
FILE2="$2"
if [ -f $FILE2 ]; then
tmp2=$(cat $FILE2 | sed -n '/regex/,/regex/{/regex/d;p}' | sed -n '/#/!p' | sed -e s/[^:]*:// | sed /--------/,+10d)
fi
echo "You Entered $FILE2"
MyVar2=$(echo $tmp2 > my2.txt)
var=$(echo hi2.txt | sed '/^$/p' )
echo "$var"
cmp -b my.txt my2.txt

i know, i know. thats a long pipeline..my problem is that i cant seem to include anywhere in it to be able to double space it. sed G sed '/^$/p' or awk, they just really doesnt register. the sed pipeline is to long for me to do that.. ..

Anyways , what i have looks similar to the paragraph that i just typed. And probably this one when im through. the exception to this and my text file is that it has valid commands. nothing else. So it makes sense for me double space the file iim talking about and then somehow to use a loop to execute each line ( contaiing the comands ) .

i really struck. i really need help.
# 2  
Old 12-06-2008
Hi,

it is hard to understand your many sed commands. Perhaps you can
give us an example of what you have and what you want to achieve.

If would combine your first sed-command to delete all blank lines
and double-space the rest at the same time.

Code:
sed '/./!d;/./{G}' test

Note: You don't need cat. Sed can take a file as argument.
Secondly you don't need to call sed multiple times which slows
down execution speed. You can execute many commands in one sed call,
simply separate them by ";" as in the example above. Or you write
a sed script and call it with the "-f" option.

HTH Chris
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Simplifying awk/sed short pipeline

I have a file like this: FileName,Well,Sample Description,Size ,Calibrated Conc. ,Assigned Conc. ,Peak Molarity ,Area,% Integrated Area,Peak Comment,Observations 2017-11-15 - 13.49.50.D1000,EL1,Electronic Ladder,25,5.22,,321,0.803,,,Lower Marker 2017-11-15 - 13.49.50.D1000,EL1,Electronic... (6 Replies)
Discussion started by: Xterra
6 Replies

2. Shell Programming and Scripting

awk or sed: change the color of a column w/o screwing up column spacing

Hey folks. I wrote a little awk script that summarizes /proc/net/dev info and then pipes it to the nix column command to set up column spacing appropriately. Here's some example output: Iface RxMBytes RxPackets RxErrs RxDrop TxMBytes TxPackets TxErrs TxDrop bond0 9 83830... (3 Replies)
Discussion started by: ryran
3 Replies

3. Shell Programming and Scripting

A complex sed statement

I have following requirement. Say, my text file contains following patterns {2010501005|XXGpvertex|9|0|17|0|{|{30100001|XXparameter_set|@@@@{{30001002|XXparameter|!prototype_path|$AB_COMPONENTS/Sort/Sort.mpc|3|2|Pf$|@{0|}} }}@0|@315000|78500|335000|99000|114000|87000|17|And the Sort|Ab... (8 Replies)
Discussion started by: Shell_Learner
8 Replies

4. Shell Programming and Scripting

File name has double spacing, but after print it's gone

Hi, I am writing this script to find all files in a directory and print the filepath, date and file size. However, it doesnt seem to preserve double spacing file with this script. I would appreciate a pointer or 2 to get around this - printf("%s ",$i) is printing the filepath, what do... (3 Replies)
Discussion started by: nightrider
3 Replies

5. Shell Programming and Scripting

sed: How to modify files in a complex way

Hello, I am new to sed and hope that someone can help me with the following task. I need to modify a txt file which has format like this: xy=CreateDB|head.queue|head.source|head.definition|rtf.edit|rtf.task|rft.cut abc|source|divine|line4|5|true into something like: head.queue=abc... (19 Replies)
Discussion started by: pinkypunky
19 Replies

6. Shell Programming and Scripting

SED complex string replacement

sed -i 's:"ps -ef | grep $(cat $PID_FILE) | grep -v grep":"ps -C java -o pid,cmd | grep ${SERVER_NAME} | cut -d' ' -f1 | grep -v grep":g' scriptName That's what I'm attempting to do. I'm attempting to replace this: ps -ef | grep $(cat $PID_FILE) | grep -v grep with this: ps -C java -o... (5 Replies)
Discussion started by: cbo0485
5 Replies

7. Shell Programming and Scripting

Complex find grep or sed command

Haven't worked in bash for ages. did a good bit of shell scripting in regular sh, but have forgotten most of it. I have several thousand php files that now include the following line at the end of the file. There is no LF or CR/LF before it begins, it is just concatenated to the final line of... (3 Replies)
Discussion started by: sjburden
3 Replies

8. Shell Programming and Scripting

Complex sed replacement

Hi, I have a file that I would like to translate using sed. I can do some basic sed commands, but Im afraid this level is beyond me. I have this file - ...alter... .. ...65536... ... ...65536... ... ...alter... ... ...65536... etc What I would like to do is replace the first... (11 Replies)
Discussion started by: one_ring99
11 Replies

9. Shell Programming and Scripting

Complex Sed/Awk Question?

Hello, So i have this file called /apps/turnout which looks like that of the contents of the /etc/shadow (but not exactly) the file has a long list in it. basically, the contents of this file looks something similar to the following: jajajajalala:D#$#AFVAdfda lalabavisof:#%R@fafla#$... (3 Replies)
Discussion started by: SkySmart
3 Replies

10. UNIX for Dummies Questions & Answers

Complex Pipeline/Redirection/Regular Expression problem

This is a very hard unix command which I could not perform..... :( ......here it is: The file ~unx122/public/data.txt contains over 18,000 lines of text. Here are the first ten lines of the file: pagination 20657 2740 28416 31090 18145 shiner 1695 2507 9964 14512 13122 cool 29210... (1 Reply)
Discussion started by: netmaster
1 Replies
Login or Register to Ask a Question