reverse first field from the file


 
Thread Tools Search this Thread
# 1  
MySQL reverse first field from the file

Hi all,


HTML Code:
I have a file named file1as

07/25 00:10 d327490
07/25 00:55 d378299
07/25 03:58 d378299
07/25 06:14 d642035
07/25 12:44 c997126

and now i want to reverse the first filed ie 07/25 as 

25/07 00:10 d327490
25/07 00:55 d378299
25/07 03:58 d378299
25/07 06:14 d642035
25/07 12:44 c997126
kindly reply me its urgent

thanks in advance

Moderator's Comments:
Mod Comment edit by bakunin: corrected a typo in the title for easier searching. Please refrain from using "urgent" or similar buzzwords. We are not a helpdesk and tend to get grumpy on such attempted misuse. Thanks for your consideration.

Last edited by bakunin; 09-15-2012 at 08:43 PM..
# 2  
Code:
IFS="/ " while read A B C
do
        echo "$B/$A $C"
done < inputfile > outputfile

This User Gave Thanks to Corona688 For This Post:
# 3  
Hi corona ths for a prompt reply can u pls help me

i have put the above code in ascript and run it

its giving me this error

$ new.sh
new.sh: while: not found
new.sh[2]: syntax error at line 3 : `do' unexpected
# 4  
What shell are you using? It needs a bourne shell. Try putting #!/bin/sh as the first line, or running it like sh scriptname
# 5  
HI corona i have tried it as this

Code:
awk '{print $1}' inputfile|cut -c 4-5;awk '{print $1}' inputfile|cut -c 3;awk '{print $1}' inputfile|cut -c 1-2

but the output is as

Code:
25
25
.
.
.
/
/
.
.
07
07
07

---------- Post updated at 04:30 AM ---------- Previous update was at 04:23 AM ----------

Hi corona,

im using k shell

Code:
$ sh new.sh <file1> out
new.sh: while: not found
new.sh: syntax error at line 4: `do' unexpected
$ cat new.sh
#!/bin/sh
IFS="/" while read A B C
do
echo "$B/$A $C"
done

Moderator's Comments:
Mod Comment edit by bakunin: Please view this code tag video for how to use code tags when posting code and data.

Last edited by bakunin; 09-15-2012 at 08:37 PM..
# 6  
Quote:
Originally Posted by zozoo
Code:
IFS="/" while read A B C

Quote:
Originally Posted by Corona688
Code:
IFS="/ " while read A B C

can you spot the difference?

I hope this helps.

bakunin
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reverse specific field number

Hello everybody :) I have specific problem when i use rev | uniq -f 3 -c | revORIGINAL Output- (without rev | uniq -f 3 -c | rev) tibenska13 Oct 30 00:26firsth revOUTPUT- 62:00 03 tcO 31aksnebitafter uniq -f 3 -cOUTPUT- 19 62:00 03 tcO 31aksnebitafter next revOUTPUT- tibenska13 Oct 30 00:26... (7 Replies)
Discussion started by: netsys
7 Replies

2. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

3. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

4. Shell Programming and Scripting

How to reverse all columns of a file having some field separator?

Hello, I have a file: xandyandz x & y & z x*y*z*a I require output as: zandyandx z & y & x a*z*y*x here all lines have different field seperator (and & * )based on that i want to reverse the column of a file. Pl. help. (8 Replies)
Discussion started by: nehashine
8 Replies

5. Shell Programming and Scripting

Plz Help. Compare 2 files field by field and get the output in another file.

Hi Freinds, I have 2 files . one is source.txt and second one is target.txt. I want to keep source.txt as baseline and compare target.txt. please find the data in 2 files and Expected output. Source.txt 1|HYD|NAG|TRA|34.5|1234 2|CHE|ESW|DES|36.5|134 3|BAN|MEH|TRA|33.5|234... (5 Replies)
Discussion started by: i150371485
5 Replies

6. Shell Programming and Scripting

Compare two files Field by field and output the result in another file

Hi Friends, Need Help. I have file1.txt as File1.txt |123|A|7267|Hyder|Cross|Sell|7801 |995|A|7051|2008|Lunar|New|Year|Promotion|7801 |996|A|7022|Q108|Targ|Prospect|&|SSCC|Savings|Promo|7801 |997|A|7182|Q1|Feb-Apr|08|Credit|ITA|PA|SBA|Campaign|7801 File2.txt... (7 Replies)
Discussion started by: i150371485
7 Replies

7. Shell Programming and Scripting

Append 1st field from a file into 2nd field of another file

Hi, I've internally searched through forums for about 2+ hours. Unfortunately, with no luck. Although I've found some cases close to mine below, but didn't help so much. Actually, I'm in short with time. So I had to post my case. Hoping that you can help. I have 2 files, FILE1 ... (1 Reply)
Discussion started by: amurib
1 Replies

8. Shell Programming and Scripting

Appending 1st field in a file into 2nd field in another file

Hi, I've internally searched through forums for about 2+ hours. Unfortunately, with no luck. Although I've found some cases close to mine below, but didn't help so much. Actually, I'm in short with time. So I had to post my case. Hoping that you can help. I have 2 files, FILE1 ... (0 Replies)
Discussion started by: amurib
0 Replies

9. Shell Programming and Scripting

cut a field, but with reverse order

Hi Everyone, I have one a.txt: a b 001 c b b 002 c c c, not 002 c The output should be 001 002 002 If i use cut -f 3 -d' ', this does not work on the 3rd line, so i thought is any way to cut the field counting from the end? or any perl thing can do this?:confused: ... (3 Replies)
Discussion started by: jimmy_y
3 Replies

10. Shell Programming and Scripting

how to reverse file

i am using AIX -ksh how can i reverse any file ,i have already try tac cmd it is not in AIX: please help me out. (3 Replies)
Discussion started by: RahulJoshi
3 Replies

Featured Tech Videos