Shift Characters in Text


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Shift Characters in Text
# 1  
Old 06-01-2009
Shift Characters in Text

Hi
Is there a unix script that will change the text in lefthand column to text in righthand column.

0 0
1 1
10 10
100 100
1000 1000
1001 1001
1002 1002
1003 1003
1004 1004
1005 1005
1006 1006
1007 1007
1008 1008
1009 1009
101 101
1010 1010
1011 1011
1012 1012
1013 1013
1014 1014
1015 1015
1016 1016
1017 1017
1018 1018
1019 1019
102 102
# 2  
Old 06-01-2009
Not entirely sure what you are after as both columns contain the same data but if want to swap what is in the first column with what is in the second column you could do:
Code:
$ awk '{ print $2" "$1 }' inputfile > outputfile

e.g.:
Code:
$ cat inputfile
aaa bbb
ccc ddd
1000 2000
1001 2002
$ awk '{ print $2" "$1 }' inputfile > outputfile
$ cat outputfile
bbb aaa
ddd ccc
2000 1000
2002 1001
$

If you want to replace what is in the first column with what is in the second column then you could do:
Code:
$ awk '{ print $2" "$2 }' inputfile > outputfile

e.g.
Code:
~$ awk '{ print $2" "$2 }' inputfile > outputfile
$ cat outputfile
bbb bbb
ddd ddd
2000 2000
2002 2002
$


Last edited by TonyFullerMalv; 06-01-2009 at 07:54 PM.. Reason: Second option
# 3  
Old 06-02-2009
can't understand what exactly you want..?
# 4  
Old 06-02-2009
This might explain what I want to do. See attached text document.
# 5  
Old 06-02-2009
print the values of column in right justified manner refer man page of printf
# 6  
Old 06-02-2009
@ vidyadhar85
Could you please give me the command line to do this change from left justify to right justify. Tnx.
# 7  
Old 06-02-2009
Quote:
Originally Posted by 1184jap
@ vidyadhar85
Could you please give me the command line to do this change from left justify to right justify. Tnx.
use this...
Code:
 
 awk '{printf "%+4s\n",$0}' filename

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove Special Characters Within Text

Hi, I have a "|" delimited file that is exported from a database. There is one column in the file which has description/comments entered by some application user. It has "Control-M" character and "New Line" character in between the text. Hence, when i export the data, this record with the new... (4 Replies)
Discussion started by: tarun.trehan
4 Replies

2. UNIX for Dummies Questions & Answers

How to delete text between two characters in line?

Hi, I have a large text file with the following format: >gi|347545744|gb|JN204951.1| Dismorphia spio voucher 5 ATCAAATTCCTTCCTCTCCTTAAA >gi|17544664774|gb|WN204922.32| Rodapara nigens gene region CCGGGCAAATTCCTTCCTCTCCTTAAA >gi|555466400|gb|SG255122.8| Bombyx mandariana genbank 3... (1 Reply)
Discussion started by: euspilapteryx
1 Replies

3. Shell Programming and Scripting

Check if the text file has more than 2 characters

Guys, I know that the below command will cut the 13th field from test.txt file awk -F"|" '{print $13}' test.txt The answer would be, CA CN Ohio If we see the 3 rd one, it has more than 2 characters. So i wanted to check this in if condition and i want to get the output if the 13th... (4 Replies)
Discussion started by: AraR87
4 Replies

4. UNIX for Dummies Questions & Answers

Any way to get rid of ^M characters in a text file using pr?

When I use vi to see what's in the file I get this: int add1(int x) {^M return x + 1;^M} ^Mint subtract1(int x) {^M return x - 1;^M} ^Mint double_it(int x) {^M return x * 2;^M} ^Mint halve_it(int x) {^Mreturn x / 2;^M} ^Mint main() {^M int myint;^M int result;^M ... (2 Replies)
Discussion started by: Nonito84
2 Replies

5. Shell Programming and Scripting

wrapping text not exceeding 80 characters

I have a file where the text might exceed 80 characters. I want to have the maximum text lengths to be 80, and cut text from a space. I written an awk script below but does not seem to work very well { gsub("\t"," ") $0 = line $0 while (length <= WIDTH) { line = $0 ... (3 Replies)
Discussion started by: kristinu
3 Replies

6. Shell Programming and Scripting

Remove characters from text

I have a file which looks like this. I only show first 11 lines of the file followed by some text that appears at the end of every file. 1. file:///path1/path2/path3/path4/251192.dat (score 3.849384, docid 142923) 2. file:///path1/path2/path3/path4/173859.dat (score 3.831033, docid 75365) 3.... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

7. UNIX for Dummies Questions & Answers

Help with deleting characters from text file

I have a text file that looks like this: I want to delete the last character of first column in all rows so that my output looks like this: Thanks a lot! (1 Reply)
Discussion started by: evelibertine
1 Replies

8. Shell Programming and Scripting

Replacing text/characters in vi

ok, so i have the following text to replace but it's not working. can someone please help me out: :%s~awk '// {split($2,s,",");a=$1 FS s} /-/ {b=a} END{print b}'~tail -1~g I want to replace the entire awk command with tail -1. thanks (7 Replies)
Discussion started by: SkySmart
7 Replies

9. Shell Programming and Scripting

Read text from a file between two characters..

I have a requirement where i have to read from a .sh file a text lying bet characters like 'SELECT' & ';'...Please help me out in this. I am new to shell scripting. (2 Replies)
Discussion started by: goutam_igate
2 Replies

10. Shell Programming and Scripting

Display text between two words/characters

Using sed or awk, I need to display text between two words/characters. Below are two example inputs and the desired output. In a nutshell, I need the date-range value between the quotes (but only the first occurance of date-range as there can be more than one). Example One Input: xml-report... (1 Reply)
Discussion started by: cmichaelson
1 Replies
Login or Register to Ask a Question