Data manipulation with cut command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Data manipulation with cut command
# 1  
Old 07-07-2011
Data manipulation with cut command

Hi,
I need some help with the cut command, can i use it to cut a certain number of characters from string starting from the end.
say my string is like this
some junk data xyz1@pqr.com xyz2@pqr.com some more junk data
I can't exactly say how many email addresses are present in between. But the length of the junk data on both sides is always fixed.
So i got rid of the first junk string as
$echo "some junk data xyz1@yahoo.com xyz2@yahoo.com some more junk data" | cut -d " " -f 4-
output is
xyz1@pqr.com xyz2@pqr.com some more junk data
I want to get rid of "some more junk data" which has the same length but not necessarily the same content.

Pooja
# 2  
Old 07-07-2011
Code:
 
$nawk '{ for(i=1;i<=NF;i++) { if(index($i,".com")>0){print $i} }}' test
xyz1@pqr.com
xyz2@pqr.com

$cat test
some junk data xyz1@pqr.com xyz2@pqr.com some more junk data

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 07-07-2011
Pooja,

Can you please describe briefly.

Many Thanks,
Subhendu
# 4  
Old 07-08-2011
Hi,

Solution itkamaraj gave worked for me. Thank you.

---------- Post updated 07-08-11 at 12:14 AM ---------- Previous update was 07-07-11 at 05:09 AM ----------

I have another question. Say the data in between is not of a fixed length or content unlike previously where there was a matching pattern ".com" .
The length of data on either sides is the same , although the content can still vary, how do i just get the part in between:

eg ; Data is something like this :

some junk data HELLO ! some more junk data
some junk data HOW ARE YOU some more junk data

The length of some junk data and some more junk data is constant but the content in between keeps changing. How do i go about this?
# 5  
Old 07-08-2011
Try this:
Code:
~/unix.com$ echo 'some junk data xyz1@yahoo.com xyz2@yahoo.com some more junk data
some junk data HELLO ! some more junk data
some junk data HOW ARE YOU some more junk data' | awk '{print substr($0,16,length($0)-35)}'

As junk data has always the same length, you'll have to calculate the values 16 and 35
This User Gave Thanks to tukuyomi 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

Problem in extracting data using cut/awk command

Hi Everyone, I have a very simple problem and i am stuck in that from last 8 days. I tried many attempts, googled my query but all in vain. I have a text file named "test.txt" In that suppose i have contents like: Java: 1 Object oriented programming language 2 Concepts of Abstraction... (5 Replies)
Discussion started by: Abhijeet Anand
5 Replies

2. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

3. Shell Programming and Scripting

Data manipulation, Please help..

Hello, I have a huge set of data that needs to be reformatted. Here is a simple example to explain the process. I have number n=5 and a input with many numbers separated with comma: ... (11 Replies)
Discussion started by: liuzhencc
11 Replies

4. UNIX for Dummies Questions & Answers

Data Manipulation

Dear Sir, I have file input RGR001|108.28|-2.86489|100-120|RANGGAR RGR002|108.071|-2.69028|80-100|RANNGAR RGR003|108.168|-2.97053|50-80|RANNGAR RGR007|108.192722222|-2.766138889|0-50|RANGGARI want to create files by joining each rows with each rows below Output as below ... (4 Replies)
Discussion started by: radius
4 Replies

5. UNIX for Dummies Questions & Answers

Data manipulation

Hallo Team, I need to manipulate existing data file. Have a look at current data and expected data: Current Data: 27873517141 27873540000 27873515109 27873517140 27873540001 27873540000 27873501343 27873540000 27873517140 27873511292 27873645989 27873540000 27873540000... (7 Replies)
Discussion started by: kekanap
7 Replies

6. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

7. Shell Programming and Scripting

Data manipulation from one file

HI all i have a file consisting of following numbers 0000 0000 0000 0000 0000 1010 0000 0100 0000 0000 0000 1111 0000 1010 0000 0100 (3 Replies)
Discussion started by: vaibhavkorde
3 Replies

8. UNIX for Dummies Questions & Answers

Data Manipulation

Hello I am currently having problems in mapulating a certain file which contains vaious data. Belos is a sample content Event=<3190> Client IP=<151.111.11.143> DNS=<abc.sbc.com> TransCount=<139> Client IP=<150.222.133.163> DNS=<xyz.yuu.com> TransCount=<3734> Event=<3120> Client... (11 Replies)
Discussion started by: khestoi
11 Replies

9. Shell Programming and Scripting

Data manipulation with Awk

Hello guys, I'm a new member here and I need some help with the Awk application. I'm using it through the Terminal app of OSX (I'm a Mac user). I have a huge file with a large amount of data (rows of 3D cartesian coordinates). The data is typically like the following example (actually, the... (13 Replies)
Discussion started by: Cham
13 Replies

10. UNIX for Dummies Questions & Answers

data manipulation script

I have a folder called {homedata} Within this folder there are 12 subfolders 200601.......200612 Within each subfolder there are 8 sets of files Each filename commences with A B C D E F G or H, so {filename}* can be used. I am trying to write a script which will from the top level go... (1 Reply)
Discussion started by: grinder182533
1 Replies
Login or Register to Ask a Question