inserting characters based on condition


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers inserting characters based on condition
# 1  
Old 07-30-2012
inserting characters based on condition

hi
i have a file that contains the data like this

Code:
12345
12453
8990998987
0989876656
12345678
12344
133678999
12345677

i should insert "+" and "-" signs for each line i,e.,
Code:
+ 12345 
- 12453
+ 8990998987
- 0989876656
+ 12345678
- 12344
+ 133678999
- 12345677

# 2  
Old 07-30-2012
Try...
Code:
awk '{print (NR%2?"+":"-"),$0}' file1

# 3  
Old 07-30-2012
With sed (just for the fun of it!):
Code:
sed 'x
s/^+/&/
t minus
x
s/^/+ /
h
b
:minus
x
s/^/- /
h' inputfile

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Inserting n characters to beginning of line if match

I would like to insert n number of characters at the beginning of each line that starts with a given character. If possible, I would be most appreciative for a sed or awk solution. Given the data below, I would like to be able to insert either 125 spaces or 125 "-" at the beginning of every line... (6 Replies)
Discussion started by: jvoot
6 Replies

2. Shell Programming and Scripting

Inserting column data based on category assignment

please help with the following. I have 4 col data .. instrument , category, variable and value. the instruments belong to particular categories and they all measure some variables (var1 and var2 in this example), the last column is the value an instrument outputs for a variable. I have used... (0 Replies)
Discussion started by: ritakadm
0 Replies

3. Shell Programming and Scripting

Copy down based on condition

Hello: I need to copy down some data from the previous record in to the next record based on the below conditions If position 41- 59 of the current record is same as the previous record and the value of position 62 is not equal to 1 then copy the previous records value for positions... (1 Reply)
Discussion started by: techedipro
1 Replies

4. UNIX for Dummies Questions & Answers

Condition based on Timestamp (Date/Time based) from logfile (Epoch seconds)

Below is the sample logfile: Userids Date Time acb Checkout time: 2013-11-20 17:00 axy Checkout time: 2013-11-22 12:00 der Checkout time: 2013-11-17 17:00 xyz Checkout time: 2013-11-19 16:00 ddd Checkout time: 2013-11-21 16:00 aaa Checkout... (9 Replies)
Discussion started by: asjaiswal
9 Replies

5. Shell Programming and Scripting

Comment based on a condition

I want to comment 2 lines based on a condition. If THEN occurs immediately after WHEN then i have to comment both the lunes For example : $cat file1.txt CASE WHEN THEN 1 WHEN c1= 'I' AND c2= '0' THEN 2 So in this example i want to... (2 Replies)
Discussion started by: ashwin3086
2 Replies

6. Shell Programming and Scripting

Condition based concatenation.

Hello, I am looking for concatenating the lines based on conditions. Below are the contents of the file: Infile: ----- Test1.PO_Itm COLUMN GAC_DT. Test1.PO_Itm COLUMN (PRODTCD ,PLNTCD). Test1.PO_Itm COLUMN PLNTCD. Test1.PO_Itm COLUMN ACTVIND. Test2.RgnToTerrtryGPI COLUMN... (3 Replies)
Discussion started by: indrajit_u
3 Replies

7. UNIX for Dummies Questions & Answers

Inserting control characters at the end of each line

How to add control characters at the end of each line in a file? Can anyone help me with this? Thanks, Shobana (2 Replies)
Discussion started by: Shobana_s
2 Replies

8. Shell Programming and Scripting

transpose based on condition

Hi, I have the oracle table coulns in an order like date, state1, state2....state9 and i need to prepare data from the script output for loading in to this table The script is #!/bin/ksh /usr/xpg4/bin/awk -F"-" '{print $2,$4}' /aemu/ErrorLogs/data/MissingCGIcount.txt |... (5 Replies)
Discussion started by: aemunathan
5 Replies

9. Shell Programming and Scripting

vi : inserting non-printing characters

I am trying to edit a syslinux msg file. I want to precede color codes with control characters. I have tried insert mode, then control v followed by the color code; however, I continue to get " [O " if I type the color code or enter ESC mode. How can I just insert say " ^L " ? (2 Replies)
Discussion started by: cstovall
2 Replies

10. Shell Programming and Scripting

inserting characters before each line...

Hi , the fog is fulling my brain after holidays , somebody can help me ? I have a file in input like that : toto tata tutu and trying with awk to insert the compete file string as : /dir1/dir2/toto /dir1/dir2/tata /dir1/dir2/tutu i used to write : awk 'BEGIN {FS="\\"} {print... (4 Replies)
Discussion started by: Nicol
4 Replies
Login or Register to Ask a Question