Separate fields


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Separate fields
# 1  
Old 03-31-2010
Separate fields

Hi everyone!

I have a field like that:

Quote:
xxxxyyyRfffhhhhh
aaFbbbdddccc
I need to keep
Quote:
var1=xxxxyyy
var2=R
var3=fffhhhhh

var1=aa
var2=F
var3=bbbdddccc
I don't know how to use the Capital character like a separator and how to keep only this one...
I guess sed could do something like that...

ThanksSmilie
# 2  
Old 03-31-2010
Using sed ....

Code:
# echo "xxxxyyyRfffhhhhh" | sed "s/\(.*\)[A-Z]\(.*\)/\1/"
xxxxyyy
# echo "xxxxyyyRfffhhhhh" | sed "s/\(.*\)[A-Z]\(.*\)/\2/"
fffhhhhh
#

Thanks,
Penchal

---------- Post updated at 04:50 AM ---------- Previous update was at 04:48 AM ----------

using awk

Code:
# echo "xxxxyyyRfffhhhhh" | awk -F'[A-Z]' '{print $1,$2}'
xxxxyyy fffhhhhh


Last edited by radoulov; 03-31-2010 at 06:53 AM.. Reason: Please use code tags!
# 3  
Old 03-31-2010
Thanks!!

And how to keep the Capital character?

I tried sed "s/\(.*\)([A-Z])\(.*\)/\2/" but it didn't work... Do you have a solution?

---------- Post updated at 10:00 AM ---------- Previous update was at 09:54 AM ----------

sed "s/\(.*\)\([A-Z]\)\(.*\)/\2/" is working!!

Great thank you!
# 4  
Old 03-31-2010
try this
Code:
 
$ echo "xxxxyyyRfffhhhhh" |awk -F[A-Z] '{printf "%s\n%s\n%s\n",$1,substr($0,length($1)+1,1),$2}
xxxxyyy
R
fffhhhhh

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Is there a UNIX command that can compare fields of files with differing number of fields?

Hi, Below are the sample files. x.txt is from an Excel file that is a list of users from Windows and y.txt is a list of database account. $ head -500 x.txt y.txt ==> x.txt <== TEST01 APP_USER_PROFILE USER03 APP_USER_PROFILE TEST02 APP_USER_EXP_PROFILE TEST04 APP_USER_PROFILE USER01 ... (3 Replies)
Discussion started by: newbie_01
3 Replies

2. Shell Programming and Scripting

awk to print line is values between two fields in separate file

I am trying to use awk to find all the $3 values in file2 that are between $2 and $3 in file1. If a value in $3 of file2 is between the file1 fields then it is printed along with the $6 value in file1. Both file1 and file2 are tab-delimited as well as the desired output. If there is nothing to... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. Shell Programming and Scripting

Separate fields

awk 'NF==2{s=$1;next}{$(NF+1)=s}1' sort.txt > output.txt A_16_P32713632 chr10 90695750 90695810 ACTA2 A_16_P32713635 chr10 90696573 90696633 ACTA2 A_16_P32713680 chr10 90697419 90697479 ACTA2 The command above outputs the data as a string separated by a space in 1 field. I can not... (6 Replies)
Discussion started by: cmccabe
6 Replies

4. Shell Programming and Scripting

Splitting a column in two separate fields

for making a summary I have a CSV file which is transformed to .DAT. I have an AWK file which is supposing to do the mapping of the DAT file. The code from the AWK file is the one below. The content of the DAT file looks like this (tab separated): ODT AGE CDT CO SEX TIME VALUE COMMENT ... (1 Reply)
Discussion started by: grikoss
1 Replies

5. UNIX for Dummies Questions & Answers

using sed delete a line from csv file based on specific data in two separate fields

Hello, :wall: I have a 12 column csv file. I wish to delete the entire line if column 7 = hello and column 12 = goodbye. I have tried everything that I can find in all of my ref books. I know this does not work /^*,*,*,*,*,*,"hello",*,*,*,*,"goodbye"/d Any ideas? Thanks Please... (2 Replies)
Discussion started by: Chris Eagleson
2 Replies

6. Shell Programming and Scripting

awk: Print fields between two delimiters on separate lines and send to variables

I have email headers that look like the following. In the end I would like to accomplish sending each email address to its own variable, such as: user1@domain.com='user1@domain.com' user2@domain.com='user2@domain.com' user3@domain.com='user3@domain.com' etc... I know the sed to get rid of... (11 Replies)
Discussion started by: tay9000
11 Replies

7. Shell Programming and Scripting

separate the file according to the number of fields

I have a file which is delimetered by ',' i need to filter out a file with respect to the number of fileds in each line. a,s,d,f,g,h,j,k,l 1,2,3,3,4,5,6,7,6 a,2,3 4,5,6,7 in this i neeed to filter out the lines with 8 column to another file and rest to another file. so ... (3 Replies)
Discussion started by: ratheeshjulk
3 Replies

8. Shell Programming and Scripting

How to create a CSV File by reading fields from separate files

SHELL SCRIPT Hi, I have 3 separate files within a folder. Every File contains data in a single column like File1 contains data mayank sushant dheeraj File2 contains DSA_AT MG_AT FLAT_09 File3 contains data 123123 232323 (2 Replies)
Discussion started by: mayanksargoch
2 Replies

9. Shell Programming and Scripting

awk sed cut? to rearrange random number of fields into 3 fields

I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want. The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
Discussion started by: axo959
4 Replies

10. UNIX for Dummies Questions & Answers

Separate special character fields

Hi, I have a file with User ID and User Name. Sometimes the file has speical characters in the USer ID and it creates problems. I want to allow all those fields to be processed which have only numbers and characters. I do NOT want to process those fields with Speical Characters. How... (1 Reply)
Discussion started by: baanprog
1 Replies
Login or Register to Ask a Question