You've got some serious quoting issues.
This should provide you with an example. Prints 'x' if the value in column 1 of the input is not 1, 2 or 3, otherwise translates it.
Your code works if the record contains only 1 letter.
But what if it contains a string of letters instead.
How do I make the difference between the end of the string and an unknown number?
input:
output:
Last edited by beca123456; 09-18-2012 at 11:04 PM..
However I cannot use the split function as I will have further to deal with substrings of length 2 starting at different positions.
input:
output:
I tried to modify your code but it is still the same issue. It adds an extra "X" at the end of every record:
I cannot make the difference between the end of the string and an unknown index (bold line of the code below):
You are getting the extra X at the end because you are executing your loop one time more than you have pairs in your string. This is the way I would have coded it:
There isn't any bound checking to see that the word passed in is an even number of characters. You could also make the function accept both starting and ending positions in the word in addition to the word.
In my opinion, it's bad form to reference field values (e.g. $1) in a function. Better to pass in the contents of the field that you wish to operate on.
If you want to use a while loop (more cumbersome), then you'll need to 'look ahead' before looping. Something like this:
In my opinion, it's bad form to reference field values (e.g. $1) in a function. Better to pass in the contents of the field that you wish to operate on.
I don't get it. What is the difference between the field value (e.g. $1) and the content of the field? Is it not the same at the end?
I managed to go farther with your code and added a for loop after to increment the start position:
it returns:
However, if I want farther to extend the code and refer to this field, for example to print only string without X (as a beginning), is there any way to use again the term "$1" in the rest of the script?
Even when I re-assign the value to $1 it doesn't work!
Last edited by beca123456; 09-20-2012 at 04:49 AM..
logs:
"/home/abc/public_html/index.php"
"/home/abc/public_html/index.php"
"/home/xyz/public_html/index.php"
"/home/xyz/public_html/index.php"
"/home/xyz/public_html/index.php"
how to use "cut" or "awk" or "sed" to get the following result:
abc
abc
xyz
xyz
xyz (8 Replies)
HP rp5450 (L2000)
running HP-UX 11.11B
Using DLT 7000 and DLT 4000 tape drives for nightly full backups
Backup jobs created by SAM
DLT 7000 cron entry is as follows:
00 2 * * 1-6 /usr/sam/lbin/br_backup DLT FULL Y /dev/rmt/0m /var/sam/graphLCAa17036 root Y 1 N > /var/sam/SAM_br_msgs 2>&1... (1 Reply)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
Hello,
I am working on solving an NP-Complete problem, so it is very important that operations and data with limited integer-argument ranges be computed using immutable look-up-tables contained entirely in CPU cache. Retrieval of the look-up-table data must never leave the CPU once initially... (6 Replies)
I have files that store multiple data points for the same device "vertically" and include multiple devices. It repeats a consistant pattern of lines where for each line:
Column 1 is a common number for the entire file and all devices in that file
Column 2 is a unique device number
Column 3 is... (7 Replies)
I was writing a awk function and had a error I was wondering about. It revolves around a Multidimensional array starting with ord
example:
if ( _e == 5 ) {
lmrb=$5 ; lmtb=$6 ; larb=$7 ;
latb=$8
}
... (2 Replies)
I am attempting to write a awk script that reads in a file after awk array elements are assigned and using those elements while reading in the new file. Does this make sense?
/pattern/ {tst=$3}
(( getline < "file" ) > 0 ) {
x=x " "tst
}
When I print tst in the END statement it... (9 Replies)
Hi Friends,
Can any of you explain me about the below line of code?
mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`
Im not able to understand, what exactly it is doing :confused:
Any help would be useful for me.
Lokesha (4 Replies)