Sponsored Content
Top Forums Shell Programming and Scripting Bash Script to read a file and parse each record Post 302396706 by 3vilwyatt on Friday 19th of February 2010 05:53:43 AM
Old 02-19-2010
Thanks for your reply guys. i appreciate it.

now i am trying something like this to work.
- read the csv file
- put the lines in a row array
- next loop would be to parse each row to get the columns

csv file
Code:
Record Type#Batch Job ID#Batch Number#FileCreation Date#FileCreation Time#Production/Test Fileindicator#File Character
H#0002#0002#20100218#17.25#P#barani

Record Type#A#B#C#D#E#F#G#H#J#K#L
1#2#3#4#5#6#7#8#9#10#11

Record Type#NumberOFRecords
T#4500

N

script:
Code:
#!/bin/bash
i=0
cat 1.csv | while read fileline
do
echo "$fileline"
row[i]=$fileline]
i=$(($i+1))
done

j=0
while [ $j -le $i ]
do
col1=$( cut –f 2-7  -d '#' –s $row[i])
echo "first char done"
col2=$( cut –f 1,3-7  -d '#' –s $row[i])
echo "sec char done"
col3=$( cut –f 1-2,4-7  -d '#' –s $row[i])
echo "3rd char done"
echo "$col1,$col2,$col3"
j=$(($j+1))
done

is this possible?
appreciate all your replies guys. thank you!

Last edited by 3vilwyatt; 02-19-2010 at 06:56 AM.. Reason: added csv file
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

read record from file

Hi all I have file f1 like this: Set AM/PM indicator to PM started|14155| Generate Error Re|7| Projected Cash Ba|741| Roll System Date |4| Projected Cash Balances started|2| Process Mark To Market started|13429| Process paydowns started|14189| Process Fixed Inc|439| Process Mark To... (3 Replies)
Discussion started by: koti_rama
3 Replies

2. UNIX for Dummies Questions & Answers

how to read record by record from a file in unix

Hi guys, i have a big file with the following format.This includes header(H),detail(D) and trailer(T) information in the file.My problem is i have to search for the character "6h" at 14 th and 15 th position in all the records .if it is there i have to write all those records into a... (1 Reply)
Discussion started by: raoscb
1 Replies

3. Shell Programming and Scripting

How to read and parse the content of csv file containing # as delimeter into fields using Bash?

#!/bin/bash i=0 cat 1.csv | while read fileline do echo "$fileline" IFS="#" flds=( $fileline ) nrofflds=${#flds} echo "noof fields$nrofflds" fld=0 while do echo "noof counter$fld" echo "$nrofflds" #fld1="${flds}" trying to store the content of line to fields but i... (4 Replies)
Discussion started by: barani75
4 Replies

4. Shell Programming and Scripting

Help w/ script to read file and parse log message

Hi, I am working on the script to parsing the specific message like "aaaa" in multiple log files like N1-***,N2-***,N3-***... The script is to find the list of lof files which contains the message "aaaa" and export the list into excel filE. Can anyone give help? Thanks (2 Replies)
Discussion started by: shyork2001
2 Replies

5. Shell Programming and Scripting

Bash script to read file location

I'm writing a bash script that reads a file location from a user, and I'm wondering how to get the script to accept tab to auto complete the directories that are input. (8 Replies)
Discussion started by: Prodiga1
8 Replies

6. Shell Programming and Scripting

Bash Shell Script to parse file

Raw Results: results|192.168.2|192.168.2.1|general/udp|10287|Security Note|For your information, here is the traceroute from 192.168.2.24 to 192.168.2.1 : \n192.168.2.24\n192.168.2.1\n\n results|192.168.2|192.168.2.1|ssh (22/tcp)|22964|Security Note|An SSH server is running on this port.\n... (2 Replies)
Discussion started by: jroberson
2 Replies

7. Shell Programming and Scripting

Bash Script Help...search then read from file: change text and pipe back...

Hello, I am trying to make a bash script that can pull data from a file and then change one part of said data. I want to search by username and pull the full line. That way there is a way to replace just one part of that line then return it back to the file. My Data is stored like: ... (1 Reply)
Discussion started by: serverfull
1 Replies

8. Shell Programming and Scripting

Read record from the text file & assign those values to variables in the script

For eg: I have sample.txt file with 4 rows of record like: user1|password1 user2|password2 user3|password3 user4|password4 The username and password is sepsrated by '|' I want to get the 1st row value from the file and assign it to two different variables(username and password) in my... (1 Reply)
Discussion started by: priya001
1 Replies

9. Shell Programming and Scripting

'Couldn't read file' error in bash script with expect, sed and awk!

Ok, so I have a bash script with an embedded expect statement. Inside of the expect statement, i'm trying to pull all of the non-comment lines from the /etc/oratab file one at a time. Here's my command: cat /etc/oratab |sed /^s*#/d\ | awk 'NR==1'|awk -F: '{print \"$1\"}'|. oraenv Now,... (0 Replies)
Discussion started by: alexdglover
0 Replies

10. Shell Programming and Scripting

BASH script to read external file to perform text replacements?

Hi all, I have a moderate size (300 lines) BASH Shell script that performs various tasks on different source reports (CSV files). One of the tasks that it performs, is to use SED to replace 'non-conforming' titles with conformant ones. For example "How to format a RAW Report" needs to become... (3 Replies)
Discussion started by: richardsantink
3 Replies
CBCODEC(1)						      Quick Database Manager							CBCODEC(1)

NAME
cbcodec - popular encoders and decoders SYNOPSIS
cbcodec url [-d] [-br] [-rs base target] [-l] [-e expr] [file] cbcodec base [-d] [-l] [-c num] [-e expr] [file] cbcodec quote [-d] [-l] [-c num] [-e expr] [file] cbcodec mime [-d] [-hd] [-bd] [-part num] [-l] [-ec code] [-qp] [-dc] [-e expr] [file] cbcodec csv [-d] [-t] [-l] [-e expr] [-html] [file] cbcodec xml [-d] [-p] [-l] [-e expr] [-tsv] [file] cbcodec zlib [-d] [-gz] [-crc] [file] cbcodec lzo [-d] [file] cbcodec bzip [-d] [file] cbcodec iconv [-ic code] [-oc code] [-ol ltype] [-cn] [-wc] [-um] [file] cbcodec date [-wf] [-rf] [-utc] [str] DESCRIPTION
This manual page documents briefly the cbcodec commands. cbcodec is a tool to use encoding and decoding features provided by Cabin. This command is used in the above format. file specifies a input file. If it is omitted, the standard input is read. OPTIONS
A summary of options is included below. For a complete description, see the file:///usr/share/doc/qdbm-doc/spex.html#cabincli. -d perform decoding (unescaping), not encoding (escaping). -br break up URL into elements. -rs resolve relative URL. -l output the tailing newline. -e expr specify input data directly. -c num limit the number of columns of the encoded data. -hd parse MIME and extract headers in TSV format. -bd parse MIME and extract the body. -part num parse MIME and extract a part. -ec code specify the input encoding, which is UTF-8 by default. -qp use quoted-printable encoding, which is Base64 by default. -dc output the encoding name instead of the result string when decoding. -t parse CSV. Convert the data into TSV. Tab and new-line in a cell are deleted. -html parse CSV. Convert the data into HTML. -p parse XML. Show tags and text sections with dividing headers. -tsv parse XML. Show the result in TSV format. Characters of tabs and new-lines are URL-encoded. -gz use GZIP format. -crc output the CRC32 checksum as hexadecimal and big endian. -ic code specify the input encoding, which is detected automatically by default. -oc code specify the output encoding, which is UTF-8 by default. -ol ltype convert line feed characters, with `unix'(LF), `dos'(CRLF), and `mac'(CR). -cn detect the input encoding and show its name. -wc count the number of characters of the input string of UTF-8. -um output mappings of UCS-2 characters and C strings of UTF-16BE and UTF-8. -wf output in W3CDTF format. -rf output in RFC 1123 format. -utc output the coordinate universal time. SEE ALSO
qdbm(3), cabin(3). AUTHOR
QDBM was written by Mikio Hirabayashi <mikio@fallabs.com>. This manual page was written by Fumitoshi UKAI <ukai@debian.or.jp>, for the Debian project (but may be used by others). Man Page 2005-05-23 CBCODEC(1)
All times are GMT -4. The time now is 11:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy