Help on Script of Copy String from column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help on Script of Copy String from column
# 8  
Old 02-27-2012
In awk:
Code:
awk '{x=$1;sub(/.$/,"",x);print x"\t"$0}' inputfile

# 9  
Old 02-27-2012
sorry, i didnt notice the output properly.

Code:
 
$ nawk '{$1=substr($1,1,length($1)-1)" "$1;print}' input.txt
PLOKIJ1234 PLOKIJ1234G 12 13 14 15
PLOKIJ1234 PLOKIJ1234E 12 13 14 15
PLOKIJ1234 PLOKIJ1234F 12 22 33 44
IJNUHB1234 IJNUHB12346 55 66 77 88
IJNUHB1234 IJNUHB12347 32 34 45 67
IJUHU345 IJUHU345D 23 23 22 33
IJUHYG23 IJUHYG23E 11 24 23 23
IJUHYG23 IJUHYG23F 77 88 99 00

This User Gave Thanks to itkamaraj For This Post:
# 10  
Old 02-27-2012
Its working fine ....

But i want do same thing Just Ex:

Input :

Code:
1 2 3 4 5 P4C1
3 4 5 6 7 P5C2
3 4 5 6 7 P18C3

i want that number after P in different column.
Code:
1 2 3 4 5 4 P4C1
3 4 5 6 7 5 P5C2
3 4 5 6 7 18 P18C3

it is possible

Last edited by asavaliya; 02-27-2012 at 07:16 AM..
# 11  
Old 02-27-2012
Code:
perl -ane '$x=$F[-1]; $x=~s/P(\d+).*/$1/; for(0..$#F-1){print "$F[$_] "}; print "$x $F[-1]\n"' inputfile

This User Gave Thanks to balajesuri For This Post:
# 12  
Old 02-27-2012
sed

Hi,

Try this,

Code:
sed 's/ P\([0-9][0-9]*\)\([A-Z][A-Z0-9]*\)$/ \1 P\1\2/g' file_name

Cheers,
RangaSmilie
This User Gave Thanks to rangarasan For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to find string based on pattern and search for its corresponding rows in column

Experts, Need your support for this awk script. we have only one input file, all these column 1 and column 2 are in same file and have to do lookup for values in one file(column1 and column2) but output we need in another file Need to grep row whose string contains 9K from column 1. When found... (6 Replies)
Discussion started by: as7951
6 Replies

2. UNIX for Beginners Questions & Answers

How to copy a column of multiple files and paste into new excel file (next to column)?

I have data of an excel files as given below, file1 org1_1 1 1 2.5 100 org1_2 1 2 5.5 98 org1_3 1 3 7.2 88 file2 org2_1 1 1 2.5 100 org2_2 1 2 5.5 56 org2_3 1 3 7.2 70 I have multiple excel files as above shown. I have to copy column 1, column 4 and paste into a new excel file as... (26 Replies)
Discussion started by: dineshkumarsrk
26 Replies

3. Shell Programming and Scripting

Script to check and copy column entries

Hi I have a text file (INPUT.TXT) of three columns assuming they are separated by tab. The format is given as: Column1 Column2 Column3 aaa NO aaa bbb YES asdf ccc YES yyasdf ddd NO ddd eee ... (3 Replies)
Discussion started by: my_Perl
3 Replies

4. UNIX for Advanced & Expert Users

Copy a column to another column in UNIX fixedwidth file

Hi All, I have a fixedwidth file of length 3000. Now i want to copy a column of 4 chars i.e( length 1678-1681) to column 1127 – 1171 to the same file. Please let me know how can i achive using a single command in fixed width file. Also source column length is 4 chars and target column length... (4 Replies)
Discussion started by: kiranparsha
4 Replies

5. Shell Programming and Scripting

Copy column string and put in different column

Hello Here is my input: SU3902 SU3902A NS29C (10) (00) Q1J1 0 SU3902 SU3902B VLR05 (20) (02) Q2H1 4 SU3902 SU3902C NBR22 (30) (06) Q3R5 8 SU3904 SU39047 NSV19 (11) (09) Q4k6 2 SU3904 SU39048 LB231 (12) (05) Q5k1 6 SU3904 SU39049 11VLT (13) (08) Q10C1 10 SU3904 SU3904A 25R05 (15) (06)... (3 Replies)
Discussion started by: pareshkp
3 Replies

6. UNIX for Dummies Questions & Answers

Copy column to another column in unix

Dear Gurus, I have a unix file 2 columns (# delimited) with the following data: ZTXX_CTBR1-ZBRAN1#ZTXX_CTBR1-ZBRAN_DESC# 01#CASH & CARRY# 02#DRUGSTORE - RX# 04#SUPERMARKET# 05#HYPERMARKET# 17#DRUGSTORE - NO RX# I would like to have a code that will do 2 things: 1. Delete the header... (16 Replies)
Discussion started by: chumsky
16 Replies

7. Shell Programming and Scripting

input a string and copy lines from a file with that string on it

i have a file1 with many lines. i have a script that will let me input a string. for example, APPLE. what i need to do is to copy all lines from file1 where i can find APPLE or any string that i specify and paste in on file 2 thanks in advance! (4 Replies)
Discussion started by: engr.jay
4 Replies

8. Shell Programming and Scripting

Shell Script to Search for a particular String and copy the timestamp to a variable

Hi, We Perfrom Loads to the database through a Perl script which generates a statistics file. I need to read the statistics. the Statistics file looks something like below: Process Beginning - 08-26-2010-23.41.47 DB2 CONNECTION SUCCESSFUL! Ready to process and load file: FILENAME # of... (2 Replies)
Discussion started by: Praveenkulkarni
2 Replies

9. Shell Programming and Scripting

Copy the data column to adjacent column

Hi, i have file which contains only one record like below a|b|c|.... The no of columns is not known. The expected output is as below: a|a|b|b|c|c|... Please provide me your suggestions. OS: unix Thanks, Selva (7 Replies)
Discussion started by: bharathappriyan
7 Replies

10. UNIX for Advanced & Expert Users

extracting/copy a column into a new column

Hello, Anybody out there knows how to copy a column data into a blank column using unix command? Thanks (1 Reply)
Discussion started by: folashandy
1 Replies
Login or Register to Ask a Question