LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-28-2009, 06:28 AM   #1
Srilakshmi
LQ Newbie
 
Registered: Apr 2009
Posts: 1

Rep: Reputation: 0
Unhappy How could I get output from a flat file into an array


Hi All,

Good Morning..!

I am facing some problem with Unix Shell Scripting.

I have a program which takes data from flat file checks with existing current date n time and prints out output to command prompt.

Input is Flat File....!
we need to get which rownum is matching with current date n time details and rownum should be put into an array for further use.

Can anyone pls help me on this.

Right now I had done some part of the code..



#!/bin/sh
Rownum=0;
Identify()
{
j=1
cat "$1" | while read line1
do
DATE1=`echo $line1 | cut -d " " -f5`;
DATE2=`echo $line1 | cut -d " " -f6`;
DATE3=`date -u +%x`
DATE4=`date -u +%X`
if [ $(echo $DATE3 | tr -d '/') -gt $(echo $DATE1 | tr -d '/') ]; then
if [ $(echo $DATE4 | tr -d ':') -ge $(echo $DATE2 | tr -d ':') ]; then
echo "row num:" $j
Rownum=$j
echo $Rownum
LoginId=`echo $line1 | cut -d " " -f1`;
echo Login Id : $LoginId
ServerName=`echo $line1 | cut -d " " -f2`;
ServerType=`echo $line1 | cut -d " " -f3`;
DATE5=`echo $line1 | cut -d " " -f5`;
DATE6=`echo $line1 | cut -d " " -f6`;
fi
fi
j=`expr $j + 1`;
done
}
Copy_Paste()
{
Identify "$1"
touch "$2"
for login in ${LoginId[@]}
do
echo $login
echo $LoginId" "$ServerName" "$ServerType" "A" "$DATE5" "$DATE6 >> "$2"
echo $LoginId" "$ServerName" "$ServerType" "D" "$DATE3" "$DATE4 >> "$2"
done
}
Delete_Reformat()
{
Identify "$1"
#grep -i $Rownum log.lst
x=$Rownum
echo $x
touch log.lst.new
sed -e "${x}d" log.lst > log.lst.new
mv log.lst.new log.lst
touch try1.txt
awk '$1 !~ /(^$)/' log.lst > try1.txt
mv try1.txt log.lst
}
###########################################################################
##
######
# Start of Main Menu Program
###########################################################################
##
######
clear
echo "==================================================="
echo " Select for Deactivation of HOT ID "
echo "==================================================="
echo " "
#Main Menu Option
echo " 1: Identify"
echo " 2: Copy_Paste"
echo " 3: Delete_Reformat"
echo " 4. Exit"
echo ""
echo "Make a selection (1/2): "
read sel
clear
case $sel in
1)
Identify log.lst
esac
case $sel in
2)
Copy_Paste log.lst finallog.lst
esac
case $sel in
3)
Delete_Reformat log.lst
esac
case $sel in
4)exit;
esac



j is the value which holds rownum value I need an array to hold all the valeus of j which are matching.

Pls let me know on this.

Thanks in advance

Srilakshmi
 
Old 04-28-2009, 12:00 PM   #2
Neminath
LQ Newbie
 
Registered: Jan 2009
Posts: 13

Rep: Reputation: 1
I do not know much about shell scripting.
But one bypass to your question is - if your program is correctly printing the output to console you can redirect that into another file and later you can read it and process. Don't know it helps or not.

Neminath
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to reset to 0Kb a flat file graziano1968 Linux - General 3 05-29-2007 02:43 PM
Database vs. Flat File pdeman2 Programming 32 04-17-2006 12:38 AM
Manipulating Fields Of Flat File Prasun1 General 10 09-29-2005 12:42 PM
Making VSAM file from a flat file in AIX Raghothaman AIX 2 08-25-2004 05:55 PM
Flat File QC Scripting mychl Programming 5 02-20-2004 12:53 PM


All times are GMT -5. The time now is 01:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration