Unix/Linux Forum: SED - special characters - Unix/Linux Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

SED - special characters help with SED while handling special characters Rate Topic: -----

#1 User is offline   itzz.me Icon

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 1
  • Joined: 06-June 07

Posted 06 April 2009 - 07:00 PM

Hi,

I am reading a file (GC_JAR.log) which has entries like:

320325.566, 0.0453191 secs]

I want to replace all the entries of "secs]" with just "secs"

Thus, the output should be like:

320325.566, 0.0453191 secs


I tried using sed but it's not working for some reason.

# !/bin/bash
SRC=secs\[
TRG=secs
cat GC_JAR.log | while read line
do
echo "${line}" | sed 's/"${SRC}"/"${TRG}"/g' >> GC_cycles.csv
done


Any ideas?
0

#2 User is offline   vibhor_agarwalin Icon

  • User Level: 7/10
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 574
  • Joined: 24-June 05

Posted 07 April 2009 - 08:27 AM

Use of ' won't allow your variable to be expanded.
Use " instead and you can get rid of the inner ones.
Vibhor Kumar Agarwal
0

#3 User is offline   vidyadhar Icon

  • User Level: 1/10
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 01-July 09

Posted 01 July 2009 - 11:16 PM

whay that much scrpting req for that
use simple tr
tr '\]' ' ' <filename
sed 's/\]//g' filename
awk '/\]/{gsub("\]"," ")}{print}' filename

0

#4 User is offline   fishsponge Icon

  • Administrator
  • Icon
  • Group: Admin
  • Posts: 476
  • Joined: 23-June 05
  • Gender:Male
  • Location:Cambridge, UK
  • Linux User #: 313906

Posted 02 July 2009 - 08:37 AM

personally, i'd do it this way:

cat GC_JAR.log | sed 's/secs]$/secs/g'

I tested this on my own machine, and it worked like a dream:

rhobbs@mongoose:/tmp> cat deleteme.txt
320325.566, 0.0453191 secs]
320325.566, 0.0453191 secs]
320325.566, 0.0453191 secs]
320325.566, 0.0453191 secs]
320325.566, secs] 0.0453191 secs]
rhobbs@mongoose:/tmp> cat deleteme.txt | sed 's/secs]$/secs/g'
320325.566, 0.0453191 secs
320325.566, 0.0453191 secs
320325.566, 0.0453191 secs
320325.566, 0.0453191 secs
320325.566, secs] 0.0453191 secs
rhobbs@mongoose:/tmp>

Hope this helps! :D
><> FishSponge <><

[Richard Hobbs] [HiFi Forum]

This site is funded largely out of my own pocket, so if you are feeling generous, please Posted Image Posted Image
0

#5 User is offline   vidyadhar Icon

  • User Level: 1/10
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 01-July 09

Posted 04 July 2009 - 07:22 PM

View Postfishsponge, on 02 July 2009 - 02:07 PM, said:

personally, i'd do it this way:

cat GC_JAR.log | sed 's/secs]$/secs/g'

I tested this on my own machine, and it worked like a dream:

rhobbs@mongoose:/tmp> cat deleteme.txt
320325.566, 0.0453191 secs]
320325.566, 0.0453191 secs]
320325.566, 0.0453191 secs]
320325.566, 0.0453191 secs]
320325.566, secs] 0.0453191 secs]
rhobbs@mongoose:/tmp> cat deleteme.txt | sed 's/secs]$/secs/g'
320325.566, 0.0453191 secs
320325.566, 0.0453191 secs
320325.566, 0.0453191 secs
320325.566, 0.0453191 secs
320325.566, secs] 0.0453191 secs
rhobbs@mongoose:/tmp>

Hope this helps! :D

Its not adviced to use cat command when you are using grep,sed or awk because they can take file as input...
so minimize the no of commands you use...
0

#6 User is offline   fishsponge Icon

  • Administrator
  • Icon
  • Group: Admin
  • Posts: 476
  • Joined: 23-June 05
  • Gender:Male
  • Location:Cambridge, UK
  • Linux User #: 313906

Posted 06 July 2009 - 09:14 AM

good point... i should have run sed 's/secs]$/secs/g' GC_JAR.log, of course! :D
><> FishSponge <><

[Richard Hobbs] [HiFi Forum]

This site is funded largely out of my own pocket, so if you are feeling generous, please Posted Image Posted Image
0

#7 User is offline   edidataguy Icon

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 7
  • Joined: 21-July 09

Posted 23 July 2009 - 04:42 AM

View Postfishsponge, on 06 July 2009 - 03:14 AM, said:

good point... i should have run sed 's/secs]$/secs/g' GC_JAR.log, of course! :D


I know it is a little late to respond. But just to make life easier for others who may come searching:
The above can be shortened a little by this:

Quote

sed 's/]$//' GC_JAR.log

0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Cambridge Plus :: Cambridgeshire Steam Rally :: PIC Application Design :: Classic British Motorbike Piston Rings
Unix Man Pages / Linux Man Pages :: HiFi Forum :: A14 Comments :: UNIX/Linux Forum Archives