I have a text file that has many lines, and for each line I need to extract different sections of text, then write several variables from the data.
I can split out the various sections by selecting their position on each line as the column sizes will never vary.
A sample of my text file is below
Code:
"A 16 7G12Cooper Amber 4"
"A 16 9G12Patrech Erin 4"
"A 16 12B12Donovan Brody 4"
"A 16 14G12Tanea Semira 4"
"A 16 70 G9Fink Jade 4"
"A 16 72 B8Srini Sandip 4"
"A 16 938G12Calvar Ashley 4"
the variables and selection criteria i am extracting is here
Code:
file="Names.EXT"
while read line
do
echo $line
genderage=${line:9:3} #Loc 9th character in the line and select the next 3 Char
lastnam=${line:12:20} #loc 12th character in the line and select the next 20 char
firstnam=${line:32:21} #loc 32nd character in the line and select the next 21
echo "$lastnam;$firstnam;;$gend;$age;;" >> MM_file.txt
done <"$file"
Now to my specific Question,
for the variable $genderage, I need to delete the first character ( either B or G) and write a new variable called $gend that is either M or F depending on the original letter.
the remaining number could be either a 1 or 2 digit number which I need to write to another veriable $age.
the other question is how to delete all the trailing spaces from the other 2 variables? this can be done either when selection them, or when writing them out to a new file.
$lastnam
$firstnam
TIA
Ken
Last edited by vbe; 08-29-2013 at 10:42 AM..
Reason: indent...
Did you peruse your shell's man page? This works with recent shells:
Code:
while read line
do #echo $line
gendage=${line:9:3} #Loc 9th character in the line and select the next 3 Char
gendage=${gendage##* }
[ "${gendage:0:1}" = "B" ] && gend="M" || gend="F"
age=${gendage:1}
lastnam=${line:12:20} #loc 12th character in the line and select the next 20 char
lastnam=${lastnam%% *}
firstnam=${line:32:21} #loc 32nd character in the line and select the next 21
firstnam=${firstnam%% *}
echo "$lastnam;$firstnam;;$gend;$age;;"
done < file
Cooper;Amber;;F;12;;
Patrech;Erin;;F;12;;
Donovan;Brody;;M;12;;
Tanea;Semira;;F;12;;
Fink;Jade;;F;9;;
Srini;Sandip;;M;8;;
Calvar;Ashley;;F;12;;
Thanks Rudi
I have read so much over the last few days re this and did not even think to use the shell. Looking at awk, sed and such and probably making life hard at the same time!
when at home later i will update my script accordingly
Hello Team,
I have 2 files.one contains english text and another contains Japanese. so i have to read english text and replace the text with Japanesh text in third file.
Basically, I need a help to write japanese language in text/xml file.I heard wstring does this.Not sure how do i write... (2 Replies)
Hi,
I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file.
File1 - file2 = file3
wc -l file1.txt
58112
wc -l file2.txt
55260
head -5 file1.txt
101214200123
101214700300
101250030067
101214100500... (10 Replies)
Hi friend i have input as following XML file
<?xml version="1.0"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02">
<BkToCstmrDbtCdtNtfctn>
<GrpHdr><MsgId>LBP-RDJ-TE000000-130042430010001001</MsgId><CreDtTm>2013-01-04T03:21:30</CreDtTm></GrpHdr>... (3 Replies)
Dear community,
I have to do something too hard for me :rolleyes:. I hope you can help me.
This is an output coming from Oracle query, stored in a file called query.out, there are many rows, but I read them, one by one, using while/read/done. Assuming each row is contained into $line variable... (8 Replies)
i'm trying to write a bash script that that will automatically extract zip files after the download.
i writed this script
#!/bin/bash
wget -c https://github.com/RonGokhle/kernel-downloader/zipball/master
CURRENDIR=/home/kernel-downloader
cd $CURRENDIR
rm $CURRENDIR/zipfiles 2>/dev/null
... (2 Replies)
I have 1 file that has elements as follows. Also the CVR(10) and the word "SAUCE" only appear once in the file so maybe a grep command would work?
file1
CVR( 9) = 0.385E+05, ! VEHICLE
CVR(10) = 0.246E+05, ! SAUCE
CVR(11) = 0.162E+03, ! VEHICLE
I need to extract the... (6 Replies)
Hello fourm members,
I want to write a script to extarct paticular strings from the all type of files(.sh files,logfiles,txtfiles) and redirect into a log file.
example:
I have to find the line below in the script and extract the uname and Pwds.
sqsh -scia2007 -DD0011uw01 -uciadev... (5 Replies)
Hi All,
I am having an XML tag like:
<detail sim_ser_no_1="898407109001000090"
imsi_1="452070001000090">
<security>ADM1=????</security>
<security>PIN1=????</security>
<security>PIN2=????</security>
... (2 Replies)
Hi,
This is the first time playing around with perl and need some help.
Assuming if i have a line of text that looks like this:
Date/Time=Nov 18 17:12:11;Device Name=192.168.1.1;Device IP=192.168.1.1;Device Class=IDS;Source IP=155.212.212.111;Source Name=UNKNOWN;Source Port=1679... (3 Replies)
needa c program to extract text between two delimiters from some text file.
and then storing them in to diffrent variables ?
text file like 0:
abc.txt
=========
aaaaaa|11111111|sssssssssss|333333|ddddddddd|34343454564|asass
aaaaaa|11111111|sssssssssss|333333|ddddddddd|34343454564|asass... (7 Replies)