Sponsored Content
Top Forums Shell Programming and Scripting Bash script to read a file from particular line till required line and process Post 302923602 by junior-helper on Monday 3rd of November 2014 06:31:31 PM
Old 11-03-2014
I guess this is it Smilie WARNING: There is no error checking at all!

Code:
#!/bin/bash

ufile=$1 #user file name
ulf=$2 #user line from
ult=$3 #user line to

ifile=$4 #item file name
ilf=$5 #item line from
ilt=$6 #item line to

for user in `awk -vULF=$ulf -vULT=$ult 'NR>=ULF && NR<=ULT' $ufile` ; do
 for item in `awk -vILF=$ilf -vILT=$ilt 'NR>=ILF && NR<=ILT' $ifile` ; do
  echo $user @ $item
 done
done

Demonstration:
Code:
$ for i in {1..100}; do echo user$i >>userlist; done
$ for i in {1..100}; do echo item$i >>itemlist; done
$
$ ./script.sh userlist 23 30 itemlist 60 65
user23 @ item60
user23 @ item61
user23 @ item62
user23 @ item63
user23 @ item64
user23 @ item65
user24 @ item60
user24 @ item61
user24 @ item62
user24 @ item63
user24 @ item64
user24 @ item65
user25 @ item60
user25 @ item61
user25 @ item62
user25 @ item63
user25 @ item64
user25 @ item65
user26 @ item60
user26 @ item61
user26 @ item62
user26 @ item63
user26 @ item64
user26 @ item65
user27 @ item60
user27 @ item61
user27 @ item62
user27 @ item63
user27 @ item64
user27 @ item65
user28 @ item60
user28 @ item61
user28 @ item62
user28 @ item63
user28 @ item64
user28 @ item65
user29 @ item60
user29 @ item61
user29 @ item62
user29 @ item63
user29 @ item64
user29 @ item65
user30 @ item60
user30 @ item61
user30 @ item62
user30 @ item63
user30 @ item64
user30 @ item65
$

 

10 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

how to read a file till it encounters a blank line

Hi , I want to read a file starting with "*" up to till it encounters a blank line and to redirect this output to a different file.Plz suggest how to write a script for this. e.g:- * PK Sent Email (11.23) CALYPSO 1243215 9116457 NEW TRAD FAILED Nov 23 2007 9:34AM OASYS: DPS:... (0 Replies)
Discussion started by: adityam
0 Replies

2. Shell Programming and Scripting

how to read a file till it encounters a blank line

Hi , I want to read a file starting with "*" up to till it encounters a blank line and to redirect this output to a different file.Plz suggest how to write a script for this. e.g:- * PK Sent Email (11.23) CALYPSO 1243215 9116457 NEW TRAD FAILED Nov 23 2007 9:34AM OASYS: DPS: SINGCORP invalid... (1 Reply)
Discussion started by: adityam
1 Replies

3. UNIX for Dummies Questions & Answers

how to read a file till it encounters a blank line

Hi , I want to read a file starting with "*" up to till it encounters a blank line and to redirect this output to a different file.Plz suggest how to write a script for this. e.g:- * PK Sent Email (11.23) CALYPSO 1243215 9116457 NEW TRAD FAILED Nov 23 2007 9:34AM OASYS: DPS: SINGCORP invalid... (1 Reply)
Discussion started by: adityam
1 Replies

4. UNIX for Advanced & Expert Users

Urgent Help required : awk/sed help to find pattern and delete till end of line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (1 Reply)
Discussion started by: rajan_san
1 Replies

5. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

6. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

7. Shell Programming and Scripting

Read file line by line and process the line to generate another file

Hi, i have file which contains data as below(Only sample shown, it may contain more data similar to the one shown here) i need to read this file line by line and generate an output file like the one below i.e based on N value the number of MSISDNs will vary, if N=1 then the following... (14 Replies)
Discussion started by: aemunathan
14 Replies

8. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

9. Shell Programming and Scripting

How to start reading from the nth line till the last line of a file.

Hi, For my reuirement, I have to read a file from the 2nd line till the last line<EOF>. Say, I have a file as test.txt, which as a header record in the first line followed by records in rest of the lines. for i in `cat test.txt` { echo $i } While doing the above loop, I have read... (5 Replies)
Discussion started by: machomaddy
5 Replies

10. Shell Programming and Scripting

With script bash, read file line per line starting at the end

Hello, I'm works on Ubuntu server My goal : I would like to read file line per line, but i want to started at the end of file. Currently, I use instructions : while read line; do COMMAND done < /var/log/apache2/access.log But, the first line, i don't want this. The file is long... (5 Replies)
Discussion started by: Fuziion
5 Replies
MENU_DRIVER(3)						   BSD Library Functions Manual 					    MENU_DRIVER(3)

NAME
menu_driver -- main menu handling function LIBRARY
Curses Menu Library (libmenu, -lmenu) SYNOPSIS
#include <menu.h> int menu_driver(MENU *menu, int c); DESCRIPTION
The menu_driver() function is the guts of the menu system. It takes the commands passed by c parameter and performs the requested action on the menu given. The following commands may be given to the menu driver: Command Action REQ_LEFT_ITEM Sets the new current item to be the item to the left of the current item. REQ_RIGHT_ITEM Sets the new current item to be the item to the rights of the current item. REQ_UP_ITEM Sets the new current item to be the item above the current item. REQ_DOWN_ITEM Sets the new current item to be the item below the current item. REQ_SCR_ULINE Scroll the menu one line towards the bottom of the menu window. The new current item becomes the item immediately above the current item. REQ_SCR_DLINE Scroll the menu one line towards the top of the menu window. The new current item becomes the item immediately below the current item. REQ_SCR_DPAGE Scroll the menu one page towards the bottom of the menu window. REQ_SCR_UPAGE Scroll the menu one page towards the top of the menu window. REQ_FIRST_ITEM Set the current item to be the first item in the menu. REQ_LAST_ITEM Set the current item to be the last item in the menu. REQ_NEXT_ITEM Set the new current item to be the next item in the item array after the current item. REQ_PREV_ITEM Set the new current item to be the item before the current item in the items array. REQ_TOGGLE_ITEM If the item is selectable then toggle the item's value. REQ_CLEAR_PATTERN Clear all the characters currently in the menu's pattern buffer. REQ_BACK_PATTERN Remove the last character from the pattern buffer. REQ_NEXT_MATCH Attempt to find the next item that matches the pattern buffer. REQ_PREV_MATCH Attempt to find the previous item that matches the pattern buffer. If menu_driver() is passed a command that is greater than MAX_COMMAND then the command passed is assumed to be a user defined command and menu_driver() returns E_UNKNOWN_COMMAND. Otherwise if the command is a printable character then the character represented by the command is placed at the end of the pattern buffer and an attempt is made to match the pattern buffer against the items in the menu. RETURN VALUES
The functions return one of the following error values: E_OK The function was successful. E_SYSTEM_ERROR There was a system error during the call. E_BAD_ARGUMENT One or more of the arguments passed to the function was incorrect. E_NOT_POSTED The menu is not posted. E_UNKNOWN_COMMAND The menu driver does not recognize the request passed to it. E_NO_MATCH The character search failed to find a match. E_NOT_CONNECTED The item is not connected to a menu. E_REQUEST_DENIED The menu driver could not process the request. SEE ALSO
curses(3), menus(3) NOTES
The header <menu.h> automatically includes both <curses.h> and <eti.h>. BSD
September 10, 1999 BSD
All times are GMT -4. The time now is 10:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy