Deleting characters with sed,perl,awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting characters with sed,perl,awk
# 1  
Old 09-19-2010
Tools Deleting characters with sed,perl,awk

Input:
Code:
:: gstreamer
:: xine-lib
:: xine-lib-extras

Output should be:
Code:
gstreamer xine-lib xine-lib-extras

How can it be done with sed or perl?
# 2  
Old 09-19-2010
Code:
$ ruby -ane 'print "#{$F[1]} "' file

# 3  
Old 09-19-2010
Perl:
Code:
perl -ple '$\=" ";s/[: ]//g' file

tr :P
Code:
cat file | tr -d ": " | tr "\n" " "

# 4  
Old 09-19-2010
Quote:
Originally Posted by bartus11
Perl:
Code:
perl -ple '$\=" ";s/[: ]//g' file

tr :P
Code:
cat file | tr -d ": " | tr "\n" " "

What is $\=" " ?
And for tr,input may be:
Code:
:: gstreamer
::      xine-lib
::   xine-lib-extras

# 5  
Old 09-19-2010
$\ is output record separator (it is like ORS in awk).
# 6  
Old 09-19-2010
Quote:
Originally Posted by bartus11
$\ is output record separator (it is like ORS in awk).
Ok,but there may be 4,5,infinite space characters.
# 7  
Old 09-19-2010
Quote:
Originally Posted by cola
Ok, but there may be 4,5,infinite space characters.
Infinite ?? Really ? That's a first.

Did you even try out bartus11's Perl one-liner before claiming it won't work ?

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting duplicated chunks in a file using awk/sed

Hi all, I'd always appreciate all helps from this site. I would like to delete duplicated chunks of strings on the same row(?). One chunk is comprised of four lines such as: path name starting point ending point voltage number I would like to delete duplicated chunks on the same... (5 Replies)
Discussion started by: jypark22
5 Replies

2. Shell Programming and Scripting

Need an awk / sed / or perl one-liner to remove last 4 characters with non-unique pattern.

Hi, I'm writing a ksh script and trying to use an awk / sed / or perl one-liner to remove the last 4 characters of a line in a file if it begins with a period. Here is the contents of the file... the column in which I want to remove the last 4 characters is the last column. ($6 in awk). I've... (10 Replies)
Discussion started by: right_coaster
10 Replies

3. Shell Programming and Scripting

deleting lines between patterns using sed or awk

hi, Here is excerpt from my xml file <!-- The custom module to do the authentication for LDAP --> </login-module> <login-module code="com.nlayers.seneca.security.LdapLogin" flag="sufficient"> <module-option... (1 Reply)
Discussion started by: sunrexstar
1 Replies

4. Shell Programming and Scripting

Deleting the first column with sed,awk or perl

336 brtr 256 hello Output: brtr hello How can i do this with sed,awk or perl? (5 Replies)
Discussion started by: cola
5 Replies

5. Shell Programming and Scripting

awk and sed, how to exclude certain characters

Hello everyone: I have ran into this a few times now where my skills are just not up to snuff when it comes to Unix. So, I came here to find some beard stroking Unix wizard to help me. Basically, I am using OS X 10.5 in large scale at work and sometimes I have to run some custom reports. ... (5 Replies)
Discussion started by: tlarkin
5 Replies

6. Shell Programming and Scripting

Deleting a line from a file with sed and awk?

cat file.txt fvnuiehuewf ruevhxncvkjrh zxjvurhfuwe jkhvBEGINvfnvf ijrgioe Trying to delete a line that has the pattern "BEGIN" cat sedtest filename=file.txt pattern=BEGIN sed "/^$pattern/d" "$filename" (9 Replies)
Discussion started by: cola
9 Replies

7. Shell Programming and Scripting

Deleting Doubled Block with sed or awk

hi there, i have a text file like that one: I like to delete the second block with the Start and End Line! Does anyone have a idea? Thanks for your help, Roland (4 Replies)
Discussion started by: rolandh
4 Replies

8. Shell Programming and Scripting

Extract some characters with SED or AWK

Hi, I have the following example string: today_is_a_good_day.txt The character "_" inside the string can sometimes be more or less. The solution for every string equal the count of "_" should be alway the rest after the last underline character. Result: day.txt I want to use awk... (5 Replies)
Discussion started by: climber
5 Replies

9. Shell Programming and Scripting

deleting particular lines and moving a line up using perl/sed

Hi, I need convert a dump file in the following format : (please note that line numbers are provided for easy look) Original file: 1 2007-10-2482.90 No trade 0 0.00 100000.00 2 100000.00 3 0.00 4 HOLD 5 2007-10-2589.75 Bought 1114 1114 100000.00 0.00 ... (5 Replies)
Discussion started by: sabyasm
5 Replies

10. Shell Programming and Scripting

awk/sed with special characters

i have this script that searches for a pattern. However it fails if the pattern includes some special characters. So far, it fails with the following strings: 1. -Cr 2. $Mj 3. H'412 would a sed or awk be more effective? i don't want the users to put the (\) during the search (they... (5 Replies)
Discussion started by: apalex
5 Replies
Login or Register to Ask a Question