LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 11-13-2014, 08:12 PM   #1
debumail186
LQ Newbie
 
Registered: Oct 2014
Posts: 9

Rep: Reputation: Disabled
Using Nested loops in Unix


Hello Gurus,

Hope you are having a good day..

I am trying to built some code with nested loops in unix.

Here is some background...

I have a directory , wherein everyday 2 types of files are generated ..lets say by the name 'date'*3.log and 'date'*4.log

These files have a unique layout. The command is run once everyday to generate a file everyday. What I do is a compare between the file generated today and the one generated yesterday using diff..nd something like below

diff 1.log 2.log | tail -n +2 | head -n -4 |awk '{print $2,$3,$4,$5,$6}' > 3.log

to bring it to a specific format.. and further passing it to a perl script to format it further and finally doing a grep to remove unwanted entities.

Need your help with the piece of code which I been trying to make it to work. I am trying to build 2 loops with i and j variables to help generate the final log files in the required format.

Attaching the script as well. Pls advise.

Thanks
Dev
Attached Files
File Type: txt zfs_auditlog_ship.txt (792 Bytes, 8 views)

Last edited by debumail186; 11-13-2014 at 08:14 PM.
 
Old 11-14-2014, 01:04 PM   #2
debumail186
LQ Newbie
 
Registered: Oct 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
Hi guys,

Any advise in this regard is really appreciated.

Thanks
Dev
 
Old 11-14-2014, 02:30 PM   #3
nbritton
Member
 
Registered: Jun 2013
Location: Dubuque, IA
Distribution: Red Hat Enterprise Linux, Mac OS X, Ubuntu, Fedora, FreeBSD
Posts: 87

Rep: Reputation: Disabled
Quote:
Originally Posted by debumail186 View Post
Hi guys,

Any advise in this regard is really appreciated.

Thanks
Dev
I need more information, like what does the input look like and what do you want the output to look like? Attach some examples of the log files you want to process.

A basic nested for loop is as follows:
Code:
for i in x
do
	for j in x
	do

	done
done
Here is an example:
Code:
#!/bin/bash
# box.sh

if [ $# -lt 2 ]; then
        echo "Error: you must specify two integer arguments."
        echo "Example: $0 x y"
        exit 1
fi

if ! [[ $1 =~ ^[0-9]+$ ]] ; then
        echo "Error: argument 1 is not a positive integer."
        exit 1
fi

if ! [[ $2 =~ ^[0-9]+$ ]] ; then
        echo "Error: argument 2 is not a positive integer."
        exit 1
fi

for x in $(seq $1)
do
        for y in $(seq $2)
        do
                printf .
        done
        echo
done

Last edited by nbritton; 11-14-2014 at 02:35 PM.
 
  


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
[SOLVED] Nested while loops for bash novice E-Rich6 Programming 4 11-30-2012 11:53 AM
Perl - Nested Arrays and For loops Poetics Programming 4 12-18-2009 09:14 AM
Nested for loops and arrays in C iongrey Programming 10 04-24-2009 06:25 PM
Nested Loops In Shellscripting onacorpuscle Programming 1 11-09-2006 08:42 AM
Vectors not being reset in nested loops. C++ dangerboy Programming 8 09-22-2006 06:36 PM


All times are GMT -5. The time now is 09:07 AM.

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