Sponsored Content
Full Discussion: Mix two files line by line
Top Forums Shell Programming and Scripting Mix two files line by line Post 302874443 by rbatte1 on Friday 15th of November 2013 09:45:02 AM
Old 11-15-2013
Consider this logic:-
  • You want to read a file called colours
  • For each line it contains, you want to do the following
    • You want to read a file called fruits
    • For each line, you want to display the current colour followed by the current fruit

If you are in a shell script (ksh, bash, etc.) you need to have a loop to read in each file similar to this:-
Code:
while read variable
do
   some action
done < file

Other coding options will exist for awk, sed, perl, csh and the list goes on. This is why it would be good to know what you are starting with this issue. What are you experienced in? That's normally a good way to think about things.

Is this homework perhaps? If so, there is a homework forum.


Does that help? Would you like to experiment and let us know how you get on?




Robin
These 2 Users Gave Thanks to rbatte1 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

copying from line N1 to line N2 of a file in a series of files

Dear community, I'm quite a newbie with scripting, I have this problem: I have a file with many lines and I want to copy the lines from 1 to N to file.1, from N+1 to 2N to file.2, and so on up to the end of the file I have tried with something like this (N=43 in this example): awk '{for... (2 Replies)
Discussion started by: paolalup
2 Replies

2. Shell Programming and Scripting

How to calculate mean in AWK? line by line several files, thousands of lines

I'm kinda stuck on this one, I have 7 files with 30.000 lines/file like this 050 0.023 0.504336 050 0.024 0.529521 050 0.025 0.538908 050 0.026 0.537035 I want to find the mean line by line of the third column from the files named like this: Stat-f-1.dat .... Stat-f-7.dat Stat-s-1.dat... (8 Replies)
Discussion started by: AriasFco
8 Replies

3. Shell Programming and Scripting

linux shell script to take variables from two different files line by line

Friends I need to have a shell script which will feed variables from two different files line-by-line. For example, I have two files - permission and file_name. Contents of permission is - 644 755 .... contents of file_name /file1 /file2 ..... Now I want 644 permission will be... (4 Replies)
Discussion started by: atanubanerji
4 Replies

4. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

5. Shell Programming and Scripting

Faster Line by Line String/Date Comparison of 2 Files

Hello, I was wondering if anyone knows a faster way to search and compare strings and dates from 2 files? I'm currently using "for loop" but seems sluggish as i have to cycle through 10 directories with 10 files each containing thousands of lines. Given: -10 directories -10 files... (4 Replies)
Discussion started by: agentgrecko
4 Replies

6. Shell Programming and Scripting

How to read a two files, line by line in UNIX script and how to assign shell variable to awk ..?

Input are file and file1 file contains store.bal product.bal category.bal admin.bal file1 contains flip.store.bal ::FFFF:BADC:CD28,::FFFF:558E:11C5,6,8,2,1,::FFFF:81C8:CA8B,::FFFF:BADC:CD28,1,0,0,0,::FFFF:81C8:11C5,2,1,0,0,::FFFF:81DC:3111,1,0,1,0 store.bal.... (2 Replies)
Discussion started by: veeruasu
2 Replies

7. UNIX for Dummies Questions & Answers

Script to delete files line by line in .txt document

Friends, I am in need to delete files from a directory on a regular basis. I want to place all the files to be deleted in delete .txt file and require a script to delete files, line by line from this delete.txt file. Please help me with this script as am new to unix scripting. (3 Replies)
Discussion started by: fop4658
3 Replies

8. Shell Programming and Scripting

Perl command line option '-n','-p' and multiple files: can it know a file name of a printed line?

I am looking for help in processing of those options: '-n' or '-p' I understand what they do and how to use them. But, I would like to use them with more than one file (and without any shell-loop; loading the 'perl' once.) I did try it and -n works on 2 files. Question is: - is it possible to... (6 Replies)
Discussion started by: alex_5161
6 Replies

9. Shell Programming and Scripting

Multi line log files to single line format

I want to read the log file which was generate from other command . And the output was having multi line in log files for job name and server name. But i need to make all the logs on one line Source file 07/15/2018 17:02:00 TRANSLOG_1700 Server0005_SQL ... (2 Replies)
Discussion started by: ranjancom2000
2 Replies

10. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies
sem_post(2)							System Calls Manual						       sem_post(2)

NAME
sem_post - unlock a POSIX semaphore SYNOPSIS
DESCRIPTION
is used to post the semaphore referenced by sem. The calling thread will not return from its call to unless it can either: increment the semaphore value, if there are no blocked threads on this semaphore; give the semaphore to a blocked thread, if there are any blocked threads on this semaphore; or have an error condition. If the semaphore value is < 0, the semaphore has blocked threads, waiting for it to become available (the absolute value of the semaphore's value indicates the number of waiters at that moment). If the semaphore value is >= 0, the semaphore has no waiters. If the semaphore has no waiters at the time its value is checked, the semaphore's value will be atomically incremented, with respect to the checking of its value, up to its maximum value as specified by If the semaphore has waiters at the time its value is checked, the semaphore value is not changed. Instead, the calling thread will attempt to wake up a waiter. If the semaphore has waiters having realtime priori- ties, the thread must wake up the highest priority waiter. Otherwise the thread at the head of the channel queue is woken up. When a waiter is successfully woken, the semaphore being posted will be given to the woken waiter. In other words, the state of the sema- phore remains unchanged. Instead, the semaphore being posted will be inherited by the waiter being woken from this call to If the specified semaphore referred to by sem is a named semaphore, then this semaphore must have been opened by the calling process with The calling process must have both read and write permissions on the semaphore to perform this operation. The routine may be called asyn- chronously, i.e. from a signal handler. To use this function, link in the realtime library by specifying on the compiler or linker command line. EXAMPLES
The following call to will post the semaphore sem. RETURN VALUE
A successful call to will return 0 and the calling thread would have posted the semaphore. Otherwise, the call to will return -1 with errno set to the appropriate value of the error condition. ERRORS
fails and does not perform the requested operation if any of the following conditions are encountered: [EPERM] The calling process does not have the privileges necessary to post the semaphore. [EINVAL] The argument sem does not refer to a valid semaphore. SEE ALSO
<semaphore.h>. STANDARDS CONFORMANCE
sem_post(2)
All times are GMT -4. The time now is 04:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy