Sponsored Content
Top Forums Shell Programming and Scripting reading a file extracting information writing to a file Post 302563838 by Bruble on Wednesday 12th of October 2011 09:06:42 AM
Old 10-12-2011
thanks.
The script has had to be changed due to the fact that the grep or cut command required the data to be passed in a different way otherwise the original 'line' or 'details' was altered.

Code:
#bash
#extract orders with blank address details
#
# obtain the current date
# set today to the current date ccyymmdd format
 today=`date +%c%m%d | cut -c21-28`
 echo ${today}
#
#infile
INFILE=/usr4/xj/data/XJFOMT01
echo ${INFILE}
#create a file
OUTFILE=${HOME}/inc13874.${today}.txt
if [ -f ${OUTFILE} ]
  then
    NUM=`wc -l ${OUTFILE}`
  else
    NUM=0
fi
echo ${NUM} '  ' ${OUTFILE}
#get all orders for today that have blank addresses
#perhaps place in file or on stack
   $( echo 'ODATE  ORDER  DEPOT NAD ID ' > ${OUTFILE} )
while read line
 do
   echo ${line}
   details=$( echo "${line}" | cut -c0-300 | awk 'substr($0,266,10)=="          "' |cut -c0-37 )
    DEPOT=$( echo "${details}" | cut -c0-5 )
   COM=$( echo "${details}" | cut -c6-7 )
   ORDER=$( echo "${details}" | cut -c8-13 )
   ODATE=$( echo "${details}" | cut -c14-21 )
   NADID=$( echo "${details}" | cut -c26-37 )
echo 'line ' "${ODATE}"
#if [ "${ODATE}" == "${today}" ]
#  then
#   $( echo 'ODATE ' "${ODATE}" 'ORDER ' "${ORDER}" 'DEPOT ' "${DEPOT}" 'NAD ID ' "${NADID}" >> "${OUTFILE}" )
#fi
 done < ${INFILE}
#ADDRESS=$(grep ${ORDER} XJFADT01 | cut -c47-320)
# mailx -s "blank orders inc13874" emailaddress < ${OUTFILE}
exit

The current problem is that the variables are not being populated

---------- Post updated at 02:06 PM ---------- Previous update was at 02:05 PM ----------

the
Code:
echo ${line}

returns the expected data by within do loop variables remain blank.
 

10 More Discussions You Might Find Interesting

1. Programming

Reading and Writing file on LAN

Hi gurus I am not a C programmer but I need to read and write files on a computer on LAN using IP address. Suppose on a computer that has an IP 192.168.0.2 Any help or code example. I did in JAVA using URL, but do not know how to do in ANSI-C. In java: ------- URL url = new... (3 Replies)
Discussion started by: lucky001
3 Replies

2. UNIX for Advanced & Expert Users

Reading a file and writing the file name to a param file.

Hi All, Not sure if this would be in a dummies sectiin or advanced. I'm looking for a script if someone has doen something like this. I have list of files - adc_earnedpoints.20070630.txt adc_earnedpoints.20070707.txt adc_earnedpoints.20070714.txt adc_earnedpoints.20070721.txt... (1 Reply)
Discussion started by: thebeginer
1 Replies

3. UNIX for Dummies Questions & Answers

reading ,writing,appending ,manipulating a file.

Hi my prob statement is to create a new file or to append to the 1tst file the followign chages. File 1: txt file. portfolio No a b c d abc 1 Any Any Any charString cds 2 values values values charString efd 3 can can can charString fdg 4 come come come charString... (4 Replies)
Discussion started by: szchmaltz
4 Replies

4. UNIX for Dummies Questions & Answers

Log File Writing and Reading

Hi all, I have the following shell script code which tries to sftp and writes the log into the log file. TestConnection () { echo 'Connection to ' $DESTUSERNAME@$DESTHOSTNAME $SETDEBUG if ]; then rm $SCRIPT ; fi touch $SCRIPT echo "cd" $REMOTEDIR >> $SCRIPT echo "quit" >>... (10 Replies)
Discussion started by: valluvan
10 Replies

5. Programming

I need help with file reading/writing in C

Hello everybody, I'm trying to code a program which makes the following: It sends an ARP request frame and when it gets the reply, extracts the IP address of source and writes it to a .txt file. This is gonna be done with many hosts (with a for() loop), so, the text file would look like... (2 Replies)
Discussion started by: Zykl0n-B
2 Replies

6. Shell Programming and Scripting

Reading data from DataBase and Writing to a file

Hi All, Please help me in writing data to a file in one row. In database there is a column which contains large data which does not fit in the file in one row. The column contains list of paths. I want to write these paths to a file in one row. Please find the code below writes : ... (2 Replies)
Discussion started by: rajeshorpu
2 Replies

7. Shell Programming and Scripting

Matching two file contents and extracting associated information

Hi, I am new to shell programming and need help. I have File1 with some ID numbers and File2 with ID number and some associated information. I want to match the ID numbers from File1 to contents in File2 and output a third file which pulls out the ID numbers and the associated information with... (2 Replies)
Discussion started by: newpro
2 Replies

8. Shell Programming and Scripting

Searching for Log / Bad file and Reading and writing to a flat file

Need to develop a unix shell script for the below requirement and I need your assistance: 1) search for file.log and file.bad file in a directory and read them 2) pull out "Load_Start_Time", "Data_File_Name", "Error_Type" from log file 4) concatinate each row from bad file as... (3 Replies)
Discussion started by: mlpathir
3 Replies

9. Shell Programming and Scripting

Reading and writing in same file

Hi All, Here is my requirement. I am grepping through the log files and cutting some fields from the file to generate a csv file. Now I have to check if 2nd field is having some fixed value then with the help of 4th field I have to look in same log and run another grep command to retrieve the... (11 Replies)
Discussion started by: kmajumder
11 Replies

10. Shell Programming and Scripting

Reading XML file and extracting value

Dear All, I am reading one XML file to extract value from the particular tag:- Sample xml is below:- <KeyValuePairs> <Key>TestString</Key> <Value>Test12_Pollings</Value> </KeyValuePairs> I want to read the value for the KEY tag and there will be multiple key tags :- awk... (4 Replies)
Discussion started by: sharsour
4 Replies
KSSHELL(1)						      General Commands Manual							KSSHELL(1)

NAME
ksshell -- an interactive kickstart shell SYNOPSIS
ksflatten [-i | --input INFILE] [-o | --output OUTFILE] [-v | --version VERSION] DESCRIPTION
ksshell is an interactive kickstart shell. It optionally takes an input kickstart file as the basis, allows the user to specify additional kickstart commands, and then writes out the finished kickstart file to stdout or the given file name. This program supports all the usual readline niceties including tab completion of kickstart commands and their options, though not the values those options can take. In addition to understanding all the kickstart commands, ksshell has some builtin commands of its own to make working with kickstart files in the context of a shell easier: .clear Clear the existing kickstart data, including any from INFILE. This essentially starts you over from a blank state. .quit Quit the interactive shell, either saving to the file given by OUTFILE or printing to stdout if none was given. .show Print the current kickstart file state. EXIT STATUS
ksflatten returns 0 on success, and 1 if VERSION is incorrect. If INFILE does not exist, a warning will be printed but the user will still be dumped to the interactive shell. OPTIONS
-i, --input INFILE The name of the input kickstart file. -o, --output OUTFILE Write the flattened kickstart file to OUTFILE, or stdout if no filename is given. -v, --version VERSION Use this version of kickstart syntax when processing the file, or the latest if no version is given. SEE ALSO
ksvalidator (1), ksverdiff (1) KSSHELL(1)
All times are GMT -4. The time now is 07:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy