Combine sed command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combine sed command
# 1  
Old 04-09-2012
Bug Combine sed command

Hi

I have command and i want to short it.

Code:
tr -c '[:print:][:cntrl:]' '[-*]' | sed 's/---/-/g'

I want one sed command it is possible to include tr command in to sed

Thanks
# 2  
Old 04-09-2012
Quote:
Originally Posted by asavaliya
Hi

I have command and i want to short it.

Code:
tr -c '[:print:][:cntrl:]' '[-*]' | sed 's/---/-/g'

I want one sed command it is possible to include tr command in to sed

Thanks
You got to pipe it if you want tr command.
This User Gave Thanks to kristinu For This Post:
# 3  
Old 04-09-2012
You cannot "include" the tr command into the sed programme, but you can emulate it. I think this is what you intended:

Code:
sed -E  's/[^[:print:][:cntrl:]]/-/g; s/-+/-/g  ' input-file >output-file

That will work with a BSD style sed. For Gnu, replace -E with -r.

It replaces anything that isn't a printable character, or a control character, with a single dash. Any consecutive dashes are then replaced with a single dash.
This User Gave Thanks to agama For This Post:
# 4  
Old 04-09-2012
Bug

same output// do have any other code.
# 5  
Old 04-09-2012
It would help to see a sample of your input, especially since printable characters and control characters cover pretty much everything that might be in the input. It would also help to know what you are attempting to accomplish.
This User Gave Thanks to agama For This Post:
# 6  
Old 04-09-2012
Hi Guys,

I wand find and replace all Extended ASCII Codes from all my log files.

My Log files:


Code:
/home/Kalr/PPool/Output

i have logs file in sub dir.

PHP Code:
/home/Kalr/PPool/Output/X
/home/Kalr/PPool/Output/Y
/home/Kalr/PPool/Output/
My Abc.log file input:

Code:
Extended ASCII Codes :–


Code:
l–

i want to replace with -
Code:
l-

Is there any possibility to change all Extended ASCII Codes from all log files.
# 7  
Old 04-09-2012
Interesting. I just created a test file with all characters 128 - 255 (8 bit on) and the above sed removes them as expected.

What OS and what version of sed?

My sample input with plain text scattered about:
Code:
€�‚ƒthis is a test
„...†‡ˆ‰Šand another test
‹Œ�Ž��‘'“”•--˜™š›
foo barœ�žŸ 

other stuff here: ¡¢£¤¥¦§¨©ª«¬°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ



After running the above sed:

Code:
-this is a test
-and another test
-
foo bar-

other stuff here: -



Maybe someone else has a suggestion, but it works as I would expect with both a Gnu and BSD sed.
This User Gave Thanks to agama For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk with sed to combine lines and remove specific odd # pattern from line

In the awk piped to sed below I am trying to format file by removing the odd xxxx_digits and whitespace after, then move the even xxxx_digit to the line above it and add a space between them. There may be multiple lines in file but they are in the same format. The Filename_ID line is the last line... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Efficient way to combine command

im currently running the following command to grab all arguments in front of a script, directly from the process table. # cat /tmp/allmyprocs ubuntu 9933 27793 0 03:29 pts/0 00:00:00 /bin/sh ./prying.sh ubuntu 9941 9933 0 03:29 pts/0 00:00:00 sh ubuntu 9952 9941 0 03:29... (1 Reply)
Discussion started by: SkySmart
1 Replies

3. UNIX for Dummies Questions & Answers

Combine multiple sed

Would like to convert it to one line sed -i -e '/./,$!d' term1.txt sed -i '2d' term1.txt sed -i '/^$/Q' term1.txt cat term1.txt>> test1.txt Appreciate if someone could point out the error sed -i -e '/./,$!d' -e '2d' -e '/^$/Q' term1.txt cat term1.txt>> $test1.txt ... (6 Replies)
Discussion started by: w020637
6 Replies

4. Shell Programming and Scripting

how to combine 2 files using sed

hi all I have two files file1 aaa bbb ccc ddd file2 111 222 333 444 I would like to using "SED" combine two files together Please help Thank all (3 Replies)
Discussion started by: yuesko
3 Replies

5. UNIX for Dummies Questions & Answers

What is the command use to combine line using sed

Hi all, What is the sed command use to combine line? Example: Below is an output after extracted from few commands aaa bbb ccc ddd eee fff ggg and i would like to combine all the line as shown below, aaa,bbb,ccc,ddd,eee,fff (5 Replies)
Discussion started by: 793589
5 Replies

6. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies

7. Shell Programming and Scripting

sed, grep, cut or combine?

I am a beginner at shell scripting, actually i am working on my first script right now. Anyway i have searched the world how to grep two letters from each word (it will always just be two words). For example: Example Blablabla I want my script to cut out Ex (from the first word) and Bl... (4 Replies)
Discussion started by: maskot
4 Replies

8. UNIX for Dummies Questions & Answers

SImple HELP! how to combine two lines together using sed or awk..

hi..im new to UNIX... ok i have this information in the normal shell... there are 2 lines display like this: h@hotmail.com k@hotmail.com i want it to display like this with a space betweem them h@hotmail.com k@hotmail.com the information is stored in a text file.... anyone... (10 Replies)
Discussion started by: forevercalz
10 Replies

9. UNIX for Dummies Questions & Answers

sed or grep or perl combine two lines

how do i search for the phrase "expected" on line one and "received" on line two. (there is a newline in between the two) I would like to know if/how this can be done in perl and/or grep and/or sed (3 Replies)
Discussion started by: artjaniger
3 Replies

10. UNIX for Dummies Questions & Answers

combine 2 lines (command & echo)

does anyone know how to combine 2 lines? this is what im playing around with. (filename: online, user name: prml0001, real name: primal) #!/bin/sh who | grep $1 > /dev/null if then grep $1 /etc/passwd | cut -f 5, -d : echo is logged on exit 0 else grep $1... (13 Replies)
Discussion started by: primal
13 Replies
Login or Register to Ask a Question