Visit Our UNIX and Linux User Community


solaris sed equivalent


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting solaris sed equivalent
# 1  
Old 07-23-2012
solaris sed equivalent

Hi Experts,

I am using this command to edit the file contents and also add the header to the existing file.

I prepared this command on my VM (Linux) and it worked as I wanted it to work. But on solaris its not working Smilie. Please help as it is quite urgent.

sample File:

Code:
a
b

Output File:

Code:
H,0001
a,1,2
b,1,2

Command :
Code:
sed -e "i\H,0001" -e "s/$/,1,2/" abc > abc.tmp

I searched the forum and the man pages.. but unable to find out the desired results.

Many Thanks.

Moderator's Comments:
Mod Comment Code tags for code, please.
# 2  
Old 07-23-2012
Try:
1. Use ordinary quotes instead of double ones.
2. Insert a literal newline after "i" command.

Code:
sed -e 'i\
H,0001' -e 's/$/,1,2/' abc > abc.tmp

This User Gave Thanks to yazu For This Post:
# 3  
Old 07-23-2012
I don't know if solaris has an exact equivalent, but it's simple enough to rewrite that command in plain awk without nonstandard extensions. There's nothing in there that really needs sed, extended or otherwise.
Code:
awk 'BEGIN { print "H,0001" } { print $0 ",1,2" }' input > output

This User Gave Thanks to Corona688 For This Post:
# 4  
Old 07-23-2012
AFAIK the i command in sed without the escaped newline is GNU sed only
# 5  
Old 07-23-2012
Many thanks for all your replies. awk is also working. But for a big file of around 1 Million records, awk will be faster than sed ?
# 6  
Old 07-23-2012
That depends on your implementations of awk and sed. Which is faster varies a lot from system to system.

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed Equivalent for awk/grep

Any equivalent command using awk or grep? sed -n "/^$(date --date='10 minutes ago' '+%b %_d %H:%M')/,\$p" /abc.log (7 Replies)
Discussion started by: timmywong
7 Replies

2. UNIX for Dummies Questions & Answers

A faster equivalent for this sed command

Hello guys, I'm cleaning out big XML files (we're talking about 1GB at least), most of them contain words written in a non-latin alphabet. The command I'm using is so slow it's not even funny: cat $1 | sed -e :a -e 's/&lt;*&gt;//g;/&lt;/N;//ba;s/</ /g;s/>/... (4 Replies)
Discussion started by: bobylapointe
4 Replies

3. Solaris

ignite hp-ux, which is the equivalent in solaris?

functions... ---------- Post updated at 02:51 PM ---------- Previous update was at 02:22 PM ---------- sorry i didnīt put the header in the message. i use to add this to cron in hp-ux for do the ignite 00 00 1,15 * * /opt/ignite/bin/make_net_recovery -s <IGNITE SERVER> -n 1 -P s -u -x... (5 Replies)
Discussion started by: pabloli150
5 Replies

4. Shell Programming and Scripting

SED equivalent for grep -w -f with pattern having special characters

I'm looking for SED equivalent for grep -w -f. All I want is to search a list of patterns from a file. Also If the pattern doesn't match I do not want "null returned", rather I would prefer some text as place holder say "BLANK LINE" as I intend to process the output file based on line number. ... (1 Reply)
Discussion started by: novice_man
1 Replies

5. UNIX for Dummies Questions & Answers

Equivalent of /etc/rc.local in Solaris 10

What is the equivalent of /etc/rc.local in Solaris 10? (4 Replies)
Discussion started by: proactiveaditya
4 Replies

6. Shell Programming and Scripting

ttytype equivalent command in Solaris.

Hi All, We are trying to migrate scripts from HP Unix to Solaris server, in one of the profile file following command is used to set terminal settings and export its value, "ttytype -a -s " Now the same command is not present in Solaris, could someone let me know which command should i... (0 Replies)
Discussion started by: arvindcgi
0 Replies

7. UNIX for Dummies Questions & Answers

What is the equivalent of Solaris snoop in Linux

What is the equivalent of Solaris snoop in Linux I could not find snoop in RHEL (2 Replies)
Discussion started by: santosh149
2 Replies

8. Shell Programming and Scripting

ps ax equivalent in solaris

I am using "ps ax" command in one of my scripts . AIX has x flag for ps . is there any equilent command for ps ax in solaris ? Thanks (1 Reply)
Discussion started by: talashil
1 Replies

9. Solaris

I want a command in solaris equivalent to glance in HP-UX

Hi, C an someone help me out in getting the command to get system statistics like CPU, DISK and I/O utilization in a single command instead of mpstat,vmstat and iostat. When i give sar, getting the following error, bash-3.00# sar sar: can't open /var/adm/sa/sa15 No such... (6 Replies)
Discussion started by: grrajeish
6 Replies

10. Solaris

Solaris equivalent of the ioscan command

What is the Solaris equivalent of the HP-UX "ioscan -funC" command which lists all hardware on the system? (5 Replies)
Discussion started by: etc
5 Replies

Featured Tech Videos