LinuxQuestions.org
Review your favorite Linux distribution.
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
Senior Member
 
Registered: Dec 2013
Posts: 4,865

Rep: Reputation: 1052Reputation: 1052Reputation: 1052Reputation: 1052Reputation: 1052Reputation: 1052Reputation: 1052Reputation: 1052
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: 9,437

Rep: Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 TheIndependentAquarius 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


All times are GMT -5. The time now is 07:23 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration