Change data in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change data in file
# 1  
Old 10-29-2012
MySQL Change data in file

Change File data

Input A.txt

Code:
LL725 LL725_A
LL725 SIB.ra=6
LL725 LL725_B
LL725 SIB.ra=11
LL726 LL726_A
LL726 SIB.ra=20
LL726 LL726_B
LL726 SIB.ra=6
LL726 LL726_C
LL726 SIB.ra=10

Output :-

Code:
LL725 LL725_A SIB.ra=6
LL725 LL725_B SIB.ra=11
LL726 LL726_A SIB.ra=20
LL726 LL726_B SIB.ra=6
LL726 LL726_C SIB.ra=10


Last edited by pareshkp; 10-29-2012 at 09:46 PM..
# 2  
Old 10-29-2012
try:
Code:
awk 'a{print $1,a,$2;a=x;next} {a=$2}' A.txt

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 10-29-2012
Code:
$
$ cat a.txt
LL725 LL725_A
LL725 SIB.ra=6
LL725 LL725_B
LL725 SIB.ra=11
LL726 LL726_A
LL726 SIB.ra=20
LL726 LL726_B
LL726 SIB.ra=6
LL726 LL726_C
LL726 SIB.ra=10
$
$
$ perl -lane '/=\d+$/ ? print "$x $F[1]" : do{$x=$_}' a.txt
LL725 LL725_A SIB.ra=6
LL725 LL725_B SIB.ra=11
LL726 LL726_A SIB.ra=20
LL726 LL726_B SIB.ra=6
LL726 LL726_C SIB.ra=10
$
$

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
# 4  
Old 10-29-2012
Using awk you can put pairs of records together like this:

Code:
 
awk '{ if((NR%2) == 0) { ORS="\n"}else{ORS=" "} print}' your_file_name

This uses ORS (record separator for output) feature, for even records use new line, otherwise use a space, effectlively glueing two lines with a space
These 2 Users Gave Thanks to migurus For This Post:
# 5  
Old 10-29-2012
Interesting approach migurus
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change data in one column with data from another file's column

Hello, I have this file outputData: # cat /tmp/outputData __Capacity^6^NBSC01_Licences^L3_functionality_for_ESB_switch __Capacity^2100^NBSC01_Licences^Gb_over_IP __Capacity^1837^NBSC01_Licences^EDGE_BSS_Fnc __Capacity^1816^NBSC01_Licences^GPRS_CS3_and_CS4... (1 Reply)
Discussion started by: nypreH
1 Replies

2. Shell Programming and Scripting

Change Data of first ROW

My Input : A.txt 1@A 2@B 3@C 1 4 5 2 4 5 3 4 5 B.txt 1 2 3 A B C 1 4 5 2 4 5 3 4 5 (3 Replies)
Discussion started by: asavaliya
3 Replies

3. Shell Programming and Scripting

Change Data base on Column

Base of last two column i want to change may data if Last two Column have A and C then Copy Column $4 to Column $3. Input :- DD142 0_1 DD142_A DD142_B A B DD142 1_1 DD142_B DD142_C B C DD142 2_1 DD142_A DD142_C A C DD142 3_1 DD142_A A DD142 3_2 DD142_A A DD142 4_1 DD142_B B ... (4 Replies)
Discussion started by: pareshkp
4 Replies

4. Shell Programming and Scripting

Help i want to change the data of one file and apend it into 2nd file.

Hi All, Please help i have written an ksh script, where i am actually take count of lines in one file and want to update this count to 2nd field of a new file and apend the this into an existing file. Note the below script is in for loop -------- I am apending few records in a file... (7 Replies)
Discussion started by: iamnoone
7 Replies

5. Shell Programming and Scripting

awk - change more data

Origin file has got 180 fields. I have to change olny 12th,18th and 52nd one. In a file new.txt I've got those changes in 4 fields (first one is index): I know how to change ONE field with awk array. But my question is: could it be changed more than one field in one single step? ps: one... (5 Replies)
Discussion started by: frajer
5 Replies

6. Shell Programming and Scripting

Execution Problems with scan and change file data content

Input file >Read_1 XXXXXXXXXXSDFXXXXXDS ASDRXXXXXTGAGTXXXXXT TGTGATXXXXXAXXXXGXXA . . Desired output file >Read_1 XXXXXXXXXXXXXXXXXXDS ASDRXXXXXTGAGTXXXXXT TGTGATXXXXXXXXXXXXXA . . (5 Replies)
Discussion started by: patrick87
5 Replies

7. Shell Programming and Scripting

Scan and change file data content problem

Input file >Read_1 XXXXXXXXXXSDFXXXXXDS (condition 1: After the last "X" per line, if the distance is less than or equal to 3 letter, replace those not "X" letter with "X") TREXXXXXXXSDFXXXXXDS (condition 2: Before the first "X" per line, if the distance is less than or equal to 3 letter,... (12 Replies)
Discussion started by: patrick87
12 Replies

8. Shell Programming and Scripting

Change file content based on data

I have a Transaction File coming into the system. In this file, in all records the relevant data is as follows- Position 1:10 -> Transaction Code Position 252:255 -> 4 digit business code Now based on these 2 fields I have to alter value in Transaction code (Position 1:10)... (6 Replies)
Discussion started by: varunrbs
6 Replies

9. Shell Programming and Scripting

loop through file to change some data

Hi, I have a file with the following data -0.00000 0.00000 0.00000 F F F 0.00000 0.00000 0.80000 F F F 0.50000 0.50000 0.60000 F F F 0.50000 0.50000 0.20000 F F F -0.00000 0.00000 0.40000 F F F I would like to change the last 3 lines from F F F to T T T. I tried looping each line but don't... (5 Replies)
Discussion started by: princessotes
5 Replies

10. Shell Programming and Scripting

How to change Raw data to Coloumn data fields

Dear All, I have some data file.see below. --------------ALARM CLEARING FROM SubNetwork=ONRM_RootMo,SubNetwork=AXE,ManagedElement=CGSN-------------- Alarm Record ID: 25196304 Event Time: 2006-08-28 13:41:35 Event Type: ... (1 Reply)
Discussion started by: Nayanajith
1 Replies
Login or Register to Ask a Question