LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-12-2013, 06:31 AM   #1
castor0troy
LQ Newbie
 
Registered: Apr 2013
Posts: 27

Rep: Reputation: Disabled
need to arrange a txt file in a particular format


Hello
i have a huge .txt file on server which looks like this

aa.com
ss.com
dd.com
ff.com

i want the date to be arranged in this format

1<tab>aa.com<tab>0
2<tab>ss.com<tab>0
3<tab>dd.com<tab>0
4<tab>ff.com<tab>0

can anyone help please.
 
Old 05-12-2013, 06:36 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,103

Rep: Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117
What have you tried ?. How did it not satisfy your requirements ?.
 
Old 05-12-2013, 06:55 AM   #3
castor0troy
LQ Newbie
 
Registered: Apr 2013
Posts: 27

Original Poster
Rep: Reputation: Disabled
havent tried this.
im a newbie
 
Old 05-12-2013, 08:43 AM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Code:
cat file.txt | awk '{ctr++; printf("%d \t %s \t 0\n", ctr, $1)}'
jlinkels
 
Old 05-12-2013, 08:44 AM   #5
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
You can do this easily using a script. Just try this:
Code:
#!/bin/bash
infile=/path/to/input_file
i=1
while read -r line; do
echo $line | sed "s/^/$i\t/; s/$/\t0/"
i=$((i+1))
done < $infile
Or even you can use:
Code:
~$ sed 's/$/\t0/' infile.txt  | nl

Last edited by shivaa; 05-12-2013 at 08:45 AM.
 
Old 05-12-2013, 09:42 AM   #6
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

Rep: Reputation: Disabled
Aside from the initial numbers, a search/replace operation using a text editor with regular expressions will do the job lickity split.
jdk

Last edited by jdkaye; 05-12-2013 at 09:55 AM.
 
Old 05-13-2013, 12:49 AM   #7
castor0troy
LQ Newbie
 
Registered: Apr 2013
Posts: 27

Original Poster
Rep: Reputation: Disabled
thanks guys.this worked.
 
  


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
cut first 10 lines of file master.txt and paste in ab1.txt and so on yogeshkumkar Programming 4 08-31-2011 07:23 AM
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
Creating a cron job to email me a txt file/format? NewShockerGuy Linux - General 7 05-16-2008 09:23 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
How to convert xml version of LFS-5.1.1 book to txt format? jml75 Linux From Scratch 1 06-18-2004 06:51 PM

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

All times are GMT -5. The time now is 07:37 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