leena*;
What books or tutorials are you using? e.g.: Have you found the excellent tutorials here?: http://www.grymoire.com/Unix/ |
Hi,
I've no clue about the sed command... :( can someone help in this? |
leena*;
So far, a lot of the advice has been about AWK---but there was one suggestion using SED---Did you try it? Did you try any of the AWK suggestions? Did you look at the tutorials I recommended? What exactly is it that you do not understand? |
As i've already mentioned in my last post (01-25-10, 03:52 PM ), I've created an awk command & tried it.
Suppose following is a flat file: HDR10005C100000.50ACA DTA10005A100500.50Abc DTA10003C100000.50AbA DTA10003A100700.50AbB There are no field separators (no comma or spaces are there). We have a fixed location say 3rd row, 8th column which we need to temper every time. So I wanted to create a shell script which will edit the 3rd row, 8th column of that particular file, with user provided data. So after editing, the above file will look like: HDR10005C100000.50ACA DTA10005A100500.50Abc DTA1000xC100000.50AbA DTA10003A100700.50AbB I used the following awk command: awk -v r=3 -v c=8 -v val=x 'BEGIN {}; NR != r {print}; NR==r{$c=val; print}' Leena_New where Leena_New is the name of the file. But this is trying to edit the 8th field instead of 8th column. It will be great if you could provide any help. |
leena*;
It is hard to help when you do not directly respond to our questions..... What books and tutorials are you using? Did you look at the grymoire site that I suggested? If you are trying to do this with AWK (as people have suggested), then what it the relevance of your question about SED? Did you try the suggested SED solution? Did it work? Finally, in your post above, what is the distinction between "field" and "column"? (In most contexts, these terms would be synonymous) |
What books and tutorials are you using?
I don't have any books. Did you look at the grymoire site that I suggested? I'm looking into the tutorial. But it'll take time. I posted this to see if I could get any clue in the mean time. If you are trying to do this with AWK (as people have suggested), then what it the relevance of your question about SED? I've tried this with awk, bt it doesn't seems working. I asked about sed 'coz jschiwal (Moderator) & konsolebox (Senior Member) have suggested so. Did you try the suggested SED solution? Did it work? The suggestion is nothing particular. As I've no knowledge of sed I could nt modify it to my requirement. Finally, in your post above, what is the distinction between "field" and "column"? (In most contexts, these terms would be synonymous) By Field I mean --> there are many fields(columns) in a file that are comma/space separated. By 8th Column I mean the 8th character of that row. |
Quote:
I'm not good with AWK, but I will tell you that trying to adapt someone else's suggestions without reading the man pages, tutorials, etc. is not likely to be very rewarding. Quote:
In your example, you say it is trying to edit the 8th field---but there is only ONE field In addition to the Grymoire tutorials, please go to http://tldp.org and get a copy of the Bash Guide for Beginners |
Referring to the code I posted before:
Quote:
Code:
23 Code:
s Code:
@ Code:
\(....\) We can also change it to something like: Code:
\(.\{4\}\) Code:
.... Code:
@\1wxyz@ |
Quote:
|
Quote:
Code:
awk -vuserdata="x" 'BEGIN{OFS=FS=""} Code:
# ./shell.sh |
Quote:
It's just that---at least for my pea-brain---it is not intuitive to think of every letter in a string as a field |
Thanks for your suggestions.
I wrote the following code. "!/bin/ksh echo "Enter the Row Num" read RowNum echo "Enter Column No From" read ColNumFrom echo "Enter Column No To" read ColNumTo echo "Enter File Name" read FileName #\033[$RowNum;$ColNumFrom H #awk -v r=2 -v c=3 -v val=x 'BEGIN {NR!=r; NR==r {$c=val}}' Leena.csv #r=2 #c=3 sed ''"$RoWNum"'s@\(.\{'"$ColNumFrom"'\}\)..@\1wx@' Leena_New But its' throwing an error Syntax error at line 11 : `"' is not matched. I changed the sed command to sed '"$RoWNum"s@\(.\{"$ColNumFrom"\}\)..@\1wx@' Leena_New still the same error occured... I again changed the sed to sed ''$RoWNum's@\(.\{'$ColNumFrom'\}\)..@\1wx@' Leena_New Error persisted. :( I've removed "' from the script but still the error talks about it. I'am stuck at this error... |
try this one:
Code:
sed "${RoWNums}s@\\(.\\{$ColNumFrom\\}\\)..@\\1wx@" Leena_New Code:
echo sed "${RoWNums}s@\\(.\\{$ColNumFrom\\}\\)..@\\1wx@" Leena_New |
Thanks a lot!
I used sed "$RoWNum s@\(.\{$ColNumFrom\}\)..@\1wx@" Leena_New Its working fine. :) |
Hi,
I need your help again. I've one more requirment. We have to copy a the file into a directory called My_Dir But we don't have rights to copy a file in this particular dir (no rights of cp command on this dir). So we ftp it. File_Name = "My_File" ftp host.name login: Username password: PASSWORD cd /home/abc/My_Dir mput $File_Name But I want the shell script to do this task. I tried the following: 1) REM_USER=Username REM_PASS=PASSWORD ftp host.name quote USER $REM_USER quote PASS $REM_PASS 2) ftp host.name quote Username quote PASSWORD They bring me into ftp mode. But I'm unable to do anything in FTP mode through the shell. :( Please Help |
All times are GMT -5. The time now is 08:36 PM. |