Hi Needed help for Unix Newbie


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Hi Needed help for Unix Newbie
# 1  
Old 12-31-2008
Network Hi Needed help for Unix Newbie

Hi,
Can i get some help from any of you guyz on writing Unix script.
my requirement is like reading a csv file, finding a specific pattern in the lines and repalce the string with new string and write it to another file.

My file is file ABC123.dat
Col1,Col2,Col3
102628,AB10 0,21
102628,AB10 1,21
102628,AB10 2,21
102628,AB23 5,21
102628,AB35 9,21
102628,AB53 8AA,21
102628,AB53 8AB,21
102628,AB53 8AD,21
102628,AB53 8AE,21
102628,AB53 8AG,21
102636,AB54 0,21
102636,AB54 1,21
102636,AB54 2,21
102636,AB54 3,21
102636,AB54 4,21
102636,AB54 5,21
102636,AB54 6,21
102636,AB54 7A,21
102636,AB54 7B,21
102636,AB54 7D,21
102636,AB54 7E,21
888888,A99 9,21

and i have written a small script which finds the the pattern and prints the line numbers too but i am unable to write to another file....

file=/export/home/prashant/ABC123.dat

String1="[,][A-Z][A-Z][0-9][0-9][ ][0-9][,]"
String2="[,][A-Z][0-9][0-9][ ][0-9][,]"
String3="[,][0][,]" # Replacement for the string 1 & 2 if found the pattern in the file.

if [ -f "file" ]; then
echo "File $file does not exist."
exit 1
fi
cmd=$`(grep -c "[$String1|$String2]" $file)`
line=$(grep -n "$String1" $file)
line1=$(grep -n "$String2" $file)

if [ "$cmd" != "0" ]; then

echo "the String exists what you are expecting in the Line Number"
echo "$line"
echo "$line1"
else
echo "Word does not exist."
fi

out put is something like this ....
the String exists what you are expecting in the Line Number
2:102628,AB10 0,85
3:102628,AB10 1,85
4:102628,AB10 2,85
5:102628,AB23 5,85
6:102628,AB35 9,85
12:102636,AB54 0,85
13:102636,AB54 1,85
14:102636,AB54 2,85
15:102636,AB54 3,85
16:102636,AB54 4,85
17:102636,AB54 5,85
18:102636,AB54 6,85
23:888888,A99 9,85

but i am unable to replace the string1 & string2 after finding in the file with the string3 variable to another file .....
thanks
prashant
# 2  
Old 12-31-2008
moved to "scripting" cause it's not high level programing... please watchout to post in the right subforum. thanks!
# 3  
Old 01-04-2009
Quote:
Originally Posted by prashant_jsw
but i am unable to write to another file
Advanced Bash-Scripting Guide, Chapter 19: I/O Redirection
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux newbie scripting help needed (timer)

Hi, Newbie to Linux needing some help with scripting, here. I've written a script that allows easily shutting down, rebooting, or exiting to terminal mode via a Dialog menu after logging out of X-server. In my .bash_profile I have startx followed by running my script, shutdownmenu.sh, and it... (1 Reply)
Discussion started by: Pop45398
1 Replies

2. Shell Programming and Scripting

Newbie help needed for comparing values

Being linux administrator my task is to keep the machines up and running .Everyday i get a report of list of machines that are up and running. it would be nice if i get list of machines that are shutdown in comparison to yesterdays report. for example.If there are 5 machines in my environment... (5 Replies)
Discussion started by: pinga123
5 Replies

3. OS X (Apple)

Unix Newbie...

I've a MacBook and I'm not that good to this Unix kind of a operating system, could you guys please suggest me some Unix Beginner type book to learn all the shell scripting and the whole UNIX environment (something for intermediate level)...there are thousands of books available and i don't know... (2 Replies)
Discussion started by: VasiqMz
2 Replies

4. Shell Programming and Scripting

Scripting needed for newbie

Hi, I am newbie in shell scripting I have a file name like simple.txt which comes from Mainframe systems onto windows dir every 15 minutes daily. File name is same. Every 15 minutes it updates. I need to write shell script to check if the file arrived every 15 min or not. If the new file... (4 Replies)
Discussion started by: chinniforu2003
4 Replies

5. UNIX for Dummies Questions & Answers

UNIX newbie NEWBIE question!

Hello everyone, Just started UNIX today! In our school we use solaris. I just want to know how do I setup Solaris 10 not the GUI one, the one where you have to type the commands like ECHO, ls, pwd, etc... I have windows xp and I also have vmware. I hope I am not missing anything! :p (4 Replies)
Discussion started by: Hanamachi
4 Replies

6. Programming

newbie to unix programming in C, needed a few simple prgs on these functions!

Hi all, I am a newbie to unix programming using C.. So i would like to have a few simple C programs to start off with.. I wanted programs on learning , abort,kill and raise,alarm and pause,I would also like to know how to use the vfork() in a prg It would be really great if i can have... (1 Reply)
Discussion started by: wrapster
1 Replies

7. Shell Programming and Scripting

Can we call JSP file from Unix.if so how.Please help me.Im newbie to Unix

Hi Can we call a jsp page from Unix.if so please let me know how we can.. thanks for the help in advance... thanks kumar (0 Replies)
Discussion started by: mailsukumar
0 Replies

8. HP-UX

urgent help needed on HP 9000 rp3410 server for a newbie

Hi friends i dont know whether it is the right forum to ask this or not. if its not please excuse me and please give me the link for such a forum. i am novice about HP 9000 rp3410 server and its things but i had to install and configure it. I came to know that it doesnot comes with builtin... (4 Replies)
Discussion started by: bnaravinda
4 Replies

9. Shell Programming and Scripting

Newbie to HP Unix

Hi Im a newbie to unix having been a windows guy, yes I know a swear word on here ? but part of my new job is to be trained up on Unix. On the course we were set a task to read a file that has dates times codes etc, a log file. see below as an example 2007/02/19 00:00:06: Information: Switch... (3 Replies)
Discussion started by: MyNameisEarl
3 Replies

10. UNIX Desktop Questions & Answers

Newbie help needed connecting to Internet

I have an Ultra5 with 2.56 that is connected to a network. We don't use a proxy server on the network but access the internet directly through a gateway. How do I configure the Solaris box to see the internet? Opening the internet explorer and setting HTTP; FTP etc ports to the ip of the... (3 Replies)
Discussion started by: FattyLumpkin
3 Replies
Login or Register to Ask a Question