LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-29-2014, 04:50 PM   #1
nimpoura
LQ Newbie
 
Registered: Oct 2014
Posts: 1

Rep: Reputation: Disabled
Convertion of specific parts in a txt file


Hello, I am working on Linux and i have a txt file which comprises these lines:

1 Q0 /home/nikol123/Downloads/metadata/12/119317.xml 1 -6.23956 indri
1 Q0 /home/nikol123/Downloads/metadata/20/194709.xml 2 -6.47239 indri
1 Q0 /home/nikol123/Downloads/metadata/13/120365.xml 3 -6.73307 indri
2 Q0 /home/nikol123/Downloads/metadata/25/241886.xml 2 -6.53499 indri
2 Q0 /home/nikol123/Downloads/metadata/18/175920.xml 3 -6.65065 indri........
I want to convert it in order to take:

1 Q0 119317 1 -6.23956 indri
1 Q0 194709 2 -6.47239 indri
1 Q0 120365 3 -6.73307 indri
2 Q0 241886 2 -6.53499 indri
2 Q0 175920 3 -6.65065 indri
I tried the awk command like this:
awk -F'[/ / / / / / . ]' '{print $1 " " $2 " " $9 " " $11 " " $12$13 " " $15}
but i get this result for the 1st line for example: 1 Q0 119317 1 -623956

So i wonder where is the decimal point in -623956?It should be -6.23956 . And where is the word indri? Can you propose me a different syntax for the awk command?
 
Old 10-30-2014, 03:25 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
it seems this bit: '[/ / / / / / . ]' removed the decimal point.

read awk manual, search the web - build your own solution.

nobody is going to write that script for you.
 
1 members found this post helpful.
Old 10-30-2014, 10:21 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I think you are over complicating it ... your before and after data is a simple sed to remove from first / to last /.
If you think about it for a bit this should be super easy
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Write a script that searches a txt file and write's specific data to a new file tomtweber Programming 22 02-22-2014 12:36 PM
Copy the contents of a txt file to other txt files (with similar names) by cp command Aquarius_Girl Linux - Newbie 7 07-03-2010 12:54 AM
how to get the specific text from a txt file in bash script deepakdeore2004 Programming 8 04-30-2010 06:35 AM
Searching .txt file for (specific) strings and printing them to new file Hb_Kai Linux - General 7 02-18-2010 09:09 AM
How can read from file.txt C++ where can save this file(file.txt) to start reading sam_22 Programming 1 01-11-2007 05:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration