Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › cut and paste in the same line?
New Posts  All Forums:Forum Nav:

cut and paste in the same line?  

post #1 of 2
Thread Starter 
I am on the last question of my homework and I'm a bit stuck.

"Make a copy of the corp_phones2 file and call it testcorp. Next, create a single-line command that enables you to cut characters in the fifth column of the testcorp file and paste them back to the first column in the same file. (Hint: two good solutions exist, one in which you use a semicolon and one with more finess in which you use a pipe character)"

I understand how to copy the file which is "cp corp_phones2 testcorp

and I get how to cut from the file cut which is "cut -c26-35 testcorp but beyond that I am lost. How do you paste from a from something that's already been cut? From the way I understand it, you're pasting from the clipboard.

Any help is very appreciated biggrin.gif
post #2 of 2
The problem that I think you were having is that this is done from the command line, not from an editor such as emacs. It's fairly simple to do though from the command line. First copy the file to the new file using 'cp corp_phones2 testcorp'. Then you'll cut the appropriate column using 'cut -f5 -d' ' testcorp'. Next you'll use pipe to direct the output to paste. Pasting it back in the original file using '| >> testcorp'. Then verify using the cat command. The end result is that column 5 will be added to the first column (below the original content) of the file. See the commands below for the proper syntax and remember to use a space as your delimiter when you cut. This is the aforementioned method of "more finesse".

Please make sure that you are using this as a method of understanding and not simply to complete the assignment (i.e. actually use the command and see the output not just write the response into the assignment). It will ensure that you better understand how this works and thus help you in the future, which is the goal of education after all.

[root@local ~]# cp corp_phones2 testcorp
[root@local ~]# cut -f5 -d' ' testcorp | paste >> testcorp
[root@local ~]# cat testcorp
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix
This thread is locked  
Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › cut and paste in the same line?