Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

insert predefine text in front and on a loop

Shell Programming and Scripting


Tags
insert predefine text in loop

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-12-2011
masayangbata masayangbata is offline
Registered User
 
Join Date: Feb 2011
Last Activity: 12 February 2011, 11:23 AM EST
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Data insert predefine text in front and on a loop

Hi Experts,

I wish to insert predefined text in front of every line and this needs to be in a loop because it is always expanding.

Before :
11111111
22222222
33333333
44444444

55555555
77777777
88888888
00000000

[...]

To be Inserted :
a=
b=
c=
d=

After :
a=11111111
b=22222222
c=33333333
d=44444444

a=55555555
b=77777777
c=88888888
d=00000000

[...]

I've been searching and trying but to no avail Linux

Thank you in advance,
Bata
Sponsored Links
    #2  
Old Unix and Linux 02-12-2011
Scott's Unix or Linux Image
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 18 September 2017, 4:38 AM EDT
Location: Zürich
Posts: 8,627
Thanks: 347
Thanked 1,111 Times in 959 Posts
In a loop:

Code:
CHR=(a b c d)
while read LINE; do
  [ -z "$LINE" ] && p=0 && echo && continue
  echo ${CHR[((${p:-0}%4))]}=$LINE
  ((p=p+1))
done < file1

What's always expanding? The input data or the "predefined" text?

If the latter:

Code:
awk -v c=97 '
  /^$/ { c=97; print; next }
  { printf "%c %s\n", c++, $0 }
' file1

The Following User Says Thank You to Scott For This Useful Post:
masayangbata (02-12-2011)
Sponsored Links
    #3  
Old Unix and Linux 02-12-2011
masayangbata masayangbata is offline
Registered User
 
Join Date: Feb 2011
Last Activity: 12 February 2011, 11:23 AM EST
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Hi scottn,

It worked! Thank you very much.

What I meant earlier is that the input data is always expanding.

Have a nice day!
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to insert text after a block of text? cola Shell Programming and Scripting 5 11-18-2010 09:47 AM
SED: Extracting text between first occurance of foo in front of bar ArterialTool Shell Programming and Scripting 1 08-26-2009 05:30 PM
Need to insert new text and change existing text in a file using SED iamgeethuj Shell Programming and Scripting 4 11-25-2008 02:59 AM
How to insert some constant text at beginig of each line within a text file. Muhammad Afzal Shell Programming and Scripting 4 10-30-2008 11:01 PM
Insert Text With Sed steveramsey UNIX for Dummies Questions & Answers 5 02-09-2006 08:48 AM



All times are GMT -4. The time now is 08:09 AM.