i need to cut the string in a textfile but each line has a specific way of cutting it (different lengths)
i have a for loop that gets the string line per line, then each line has to be compared:
Code:
for x in `cat tmp2.txt`; do
if[ "BAC" == _____ ]; then
echo 'BAC'
elif[ "sdf_ada" == _____]
etcetc
fi
done
sample tmp2.txt file that needs to be trim to specific length :
BAC0904102604 -> BAC
AFR0904102604 -> AFR
HHF0904102604 -> HHF
UI100904102907 ->UI10
sdf_ada_9541-9543.1 -> sdf_ada
_fsf13145533 ->fsf
note: the file is in random order.
Last edited by bakunin; 05-05-2009 at 07:07 AM..
Reason: added code-tags. Please do that yourself from now on. Thanks
if there are 1 million lines in tht file how you will do the comparison ?...
from where u will get the length of the number of characters to cut ?...
basically there are 18 patterns all in all. (18 specific length)
So what i want to do is to 'for loop' the file to get each lines, and there will be 18 if,elif,else statements.
But i dont know how to exactly cut a string that will be used as condition to the if else statements.
here is my pseudocode:
Code:
for x in `cat tmp2.txt`; do #get line per line
if[ "BAC" == _____ ]; then
echo 'BAC'
elif[ "sdf_ada" == _____]
etcetc
elif[ ... ]
fi (18x)
done
example of else-if statement (obviously not working, invented)
BAC0904102604foo
AFR0904102604bar fred
sdf_ada_9541-9543.1foo
HHF0904102604function
UI100904102907brick
sdf_ada_9541-9543.1red
_fsf13145533black
BAC0904102604yellow
sdf_ada_9541-9543.1fred
nawk -f izuma.awk tmp2.txt myTextFile
Code:
# reading the FIRST file specified on the command line.
# create an array 'arr' indexed by the FIRST field ($1) of the file with the value from the THIRD
# field ($3) of the file. Jump to the 'next' record without executing the rest of the code.
FNR==NR { arr[$1]=$3; next }
# reading the SECOND file specified on the command line.
{
# iterate through all the entries in array 'arr' - 'i' contains the INDEX to array 'arr'
# substitute a value of 'i' from the begging of the line (^) with the value of 'arr[i]'.
# 'gsub' returns the NUMBER of the performed substitutions
# add the number of the substitutions to an array 'sum' indexed by 'arr[i]'
for( i in arr)
sum[arr[i]]+=gsub("^" i, arr[i])
}
END {
# iterate through the array 'sum' outputting the total number of the performed substitutions
# per pattern/prefix
for (i in sum)
printf("[%s] -> [%d]\n", i, sum[i])
}
Last edited by vgersh99; 05-06-2009 at 08:16 AM..
Reason: comments
Hello everyone,
I don't really know anything about scripting, but I have to manage to make this script, out of necessity.
#!/bin/bash
while read -r line; do #I'm reading from a big wordlist
instructions using $line
done
Is there a way to automatically write the $line number the script... (4 Replies)
hi all
In my bash script I want to cut a line up to a specific string and keep the rest of it but only up to a ".How can I do that?I imagine something with sed..
Let's say my line is:
Jennifer Jones (student) "id:376765748587/7465674775" NewYork
and i only want to keep:
... (9 Replies)
I get a file which has all its content in a single row.
The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file.
I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Hi, I'm starting a little project with a shell script but I'm don't know how to do it. Maybe someone can help me.
I have un text file like this :
I'd like to do a script who will extract from my file from @ADDLINE1@ to @ADDLINE4@ only and I have no idea how to do this.
Any idea ?
... (7 Replies)
Hi!
I need to do the following:
(1) I wan't to extract a line of a textfile (defined by a numer) and store it into a variable...
(2) ...but I want to cut out a part of the line which is between two tokens and store just this to the variable
Example:
BlaBlaBla Bla2Bla2Bla2 *pPointerOne;... (4 Replies)
Hi,
I am working on a ksh script and I´m stuck on the following:
I have to get the pthread_id from a procstack file for a particular tid#.
---------- tid# 1274057 (pthread ID: 1800) ----------
---------- tid# 1736913 (pthread ID: 4019) ----------
---------- tid# 1478705 (pthread ID: ... (7 Replies)
I have delimited-text files ( > 4GB ) and is just one line.
OS: HP-UX 11.23
Awk / cut / sed all have line_max limitations. & unable to read one line in (Buffered-mode).
Sample file:
xxxx|adsfadf|Afdsa|adsf|afds|Asdfas|ads|Afds|Asdf| .....till forever,
I want to put a carriage... (5 Replies)
HI,
I want to cut end string from line.
e.g. i have following input line
/users/home/test.txt
I want to get end string 'test.txt' from above line and length of that end string will change and it always start after '/'.
Thanks,
Visu (7 Replies)