Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 01-06-2011, 05:48 PM   #1
LQ Newbie
Registered: Jan 2011
Posts: 1

Rep: Reputation: 0
Command Line Paste

This seems like a really simple task, but I am having quite a problem with it. I am using Unix command line tools (cut, paste, etc.) to reformat a file. I need to remove the first column of a space-delimited file, and insert a column of ascending integer IDs. I use "cut OriginalFile.txt -d ' ' -f 2- > temp.txt" to remove the first column of the original file. I use "paste IntegerIDs.txt temp.txt > FinalFormat.txt" to add one column of integer IDs. However, I wind up with the IDs appearing on a new line from the rest of the file. Here's what FinalFormat.txt looks like:
0 0 2 1
0 0 2 1
0 0 1 1
0 0 2 1
0 0 1 1
0 0 2 1
0 0 2 1
0 0 2 1
0 0 2 1
0 0 1 1

I think the problem might be with the format of my IntegerIDs.txt file. I'm guessing there might be a hidden newline character which is somehow screwing up the format of the paste command? If that's the case, what's an easy way to create a long list of ascending integers without newline characters? I've tried making the IDs file in Excel, and with a simple C# routine using the WriteLine command. Neither of these have worked. Any suggestions?
Old 01-06-2011, 06:00 PM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911
Hi, welcome to LQ!

Hard to say what causes the problem, but you may be better off using
awk for this job.
awk '{$1=NR; print $0}' OriginalFile.txt > FinalFormat.txt"



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
Copy-paste from editor to command line Flip69 Linux - Newbie 14 12-24-2010 07:51 AM
Cut and paste from command line dulli1 Linux - Newbie 9 10-12-2010 10:31 PM
How to copy-paste on command line? jameshao Linux - General 3 02-02-2009 02:14 AM
command line paste ol1v3rw Linux - Newbie 4 06-27-2006 03:36 PM
Copy Paste under command line? Stingreen Linux - General 7 02-10-2002 07:46 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:27 PM.

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