USA Linux Users Group Forum Index
Log in Register FAQ Memberlist Search USA Linux Users Group Forum Index Album

Sed Help needed

 
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Command Line Commands
View previous topic :: View next topic  
Author Message
ratan203
New Member


Joined: 10 Apr 2024
Posts: 2

PostPosted: Tue Apr 10, 2024 5:07 pm    Post subject: Sed Help needed Reply with quote

Hi All,
I'm new to sed and needed it to change the common occurence in the files.
I'm trying to replace select count(*) from employee to select count(*) from $DBNAME in my shell scripts.
I was trying to do this by the following
sed 's/^select count \(\*\) from employee/replaced employeewith $DBNAME"\nselect count(*) from $DBNAME/' $fl.old > $fl

But this is not working, I even tried using select count \(*\) , but this gives me empty file.

Can anyone guide me to what I'm missing in this.
Thanks in advance.

Regards,
Ratan


Back to top
View user's profile Send private message
crouse
Site Admin


Joined: 17 Apr 2024
Posts: 11833
Location: Iowa

PostPosted: Tue Apr 10, 2024 6:38 pm    Post subject: Reply with quote

With sed for special characters I find it easiest to use the [] brackets to designate them as special characters and not have the "expanded"


Code:

sed 's/select count([*]) from employee/select count(*) from $DBNAME/g' testsed.txt > newtestsed.txt


My testsed.txt
Quote:

select count(*) from employee blah this is a test blah
select count(*) from employee and more junk here to look at
select count(*) from employee and even more stuff


My newtestsed.txt
Quote:

select count(*) from $DBNAME blah this is a test blah
select count(*) from $DBNAME and more junk here to look at
select count(*) from $DBNAME and even more stuff


Hope this helps Wink



_________________
Veronica - Arch Linux 64-bit -- Kernel 2.6.33.4-1
Archie/Jughead - Arch Linux 32-bit -- Kernel 2.6.33.4-1
Betty/Reggie - Arch Linux (VBox) 32-bit -- Kernel 2.6.33.4-1
BumbleBee - OpenSolaris-SunOS 5.11
Back to top
View user's profile Send private message Visit poster's website AIM Address
JP
Linux Guru


Joined: 07 Jul 2024
Posts: 6671
Location: Central Montana

PostPosted: Wed Apr 11, 2024 2:56 am    Post subject: Reply with quote

ratan203 Welcome to USALUG!! Very Happy Very Happy



_________________
Dell Box - Arch Linux
Dell Lappy - DreamLinux 3.5 - Default OS
Mepis 8.0 - Backup
Back to top
View user's profile Send private message Visit poster's website
ratan203
New Member


Joined: 10 Apr 2024
Posts: 2

PostPosted: Wed Apr 11, 2024 7:17 am    Post subject: Thanks! Reply with quote

Thanks crouse.
Your solution worked!

Ratan


Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Command Line Commands All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All content © 2024-2009 - Usa Linux Users Group
This forum is powered by phpBB. © 2024-2009 phpBB Group
Theme created by phpBBStyles.com and modified by Crouse