Sponsored Content
Full Discussion: Paste and double loop
Top Forums UNIX for Dummies Questions & Answers Paste and double loop Post 302940091 by Akshay Hegde on Wednesday 1st of April 2015 08:52:51 AM
Old 04-01-2015
Quote:
Originally Posted by A-V
thanks a lot for your help, it worked nicely..
may I ask you to explain few things ?

why the dir1 structure is different from dir2 ?
Code:
dir1="/tmp/test1/*.txt"
dir2="/tmp/test2"

and what does this line do?
Code:
	file="$dir2/$filename"

I used files from dir1 as reference since you said same number of files with exactly same names, $i is file from dir1 and $file is file from dir2 to understand clearly, better you insert below line after file="$dir2/$filename"
Code:
echo "$i $file"

and filename=${i##*/} is parameter substitution is used instead of external basename program. Let me know if you still have confusion.
This User Gave Thanks to Akshay Hegde For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

aside from paste

how can i make a script or command to have output like this $cat file 10000 20000 $cat a 10000 $cat b 20000 this is the solution paste a b > file but another solution? $cat file 10000 20000 (3 Replies)
Discussion started by: kenshinhimura
3 Replies

2. UNIX for Dummies Questions & Answers

VI paste out of alignment

We have a guy at work who is trying to copy and paste from one file to another using vi and highlighting the code to copy with a mouse. Source file: xyz 123 abc 999 zyx 321 cba 999 xyz 123 abc 999 But when he pastes it he gets (I put the underlines in to show... (4 Replies)
Discussion started by: dlam
4 Replies

3. Programming

double pow (double x, double y) -- problems

This is the code and I'm wondering why line 14: a = ... and line 16: b = ... is wrong. This is the first time I've tried to use this. Please help me. #include <stdio.h> #include <math.h> // The link and how the double pow is used. // // http://www.nextdawn.nl/c-reference/pow.php //... (2 Replies)
Discussion started by: pwanda
2 Replies

4. Shell Programming and Scripting

why double brackets for array loop?

Dear All, Recently got some sample from internet search for array handle in shell script, and I can not understand why we need to put double brackets when extracting array values by this way : for ((i=0; i<${#admins}; i++)); do echo "${admins}" done if modify from double to single... (2 Replies)
Discussion started by: tiger2000
2 Replies

5. Shell Programming and Scripting

cut and paste?

hi, I have a file with content like this for an employee: EmployeeID 101 Day_type, day vacation,1/2/2009 sick day, 3/2/2009 personal day, 4/5/2009 jury duty day, 5/5/2009 how do I make the result to show: EmployeeID,Day_type,day 101,vacation,1/2/2009 101,sick day,... (6 Replies)
Discussion started by: jbchen
6 Replies

6. UNIX for Dummies Questions & Answers

Paste

paste -d "\0" ap_cntrl_total.txt.1 ap_cntrl_total.txt.2, and it shows: 01234567890911051342C091026 0000910517990000000000009105179900000000CHOPME it put space btwn 1026 and 000091 should not have space. ---------- Post updated at 03:54 PM ---------- Previous update was at 03:03 PM... (1 Reply)
Discussion started by: tjmannonline
1 Replies

7. UNIX for Dummies Questions & Answers

Rename files with sed in an until loop (double post)

I want to change the name of some of my files (mypics-0001, mypics-0002, mypics-0003.....mypics-0240) and I want to double check to see if this code is right: x=0 until do sed 's/mypics\-*/bday/g' done Would this change all of my file names to "bday0001....bday0240"? Please let me... (0 Replies)
Discussion started by: jvpike
0 Replies

8. Shell Programming and Scripting

need a perl replacement for this double for loop

hi everybody, can you help me with this? important: it has to be a pure perl code. zz.lis: accessibility arabic archivers astro audio benchmarks . . . "ls accessibility | grep -v Makefile" outputs accerciser at-poke at-spi at-spi-reference (6 Replies)
Discussion started by: pseudocoder
6 Replies

9. Shell Programming and Scripting

awk, double variable, for loop and rsh

Hello folks, I've a (perhaps) simple question. In a text file I've : server_name1: directory1 server_name2: directory2 server_name3: directory3 I want to make a loop that lets me connect and operate on every server: rsh server_name1 "ls -l directory1" I've tried with awk,... (6 Replies)
Discussion started by: gogol_bordello
6 Replies

10. Shell Programming and Scripting

paste mutiple files in a loop

file1.txt file2.txt file3.txt desired output is each file is in the same directory, hasthe same number of columns but different rows. i want to be able to paste them into one file. thanks! (5 Replies)
Discussion started by: johnkim0806
5 Replies
scandir(3)						     Library Functions Manual							scandir(3)

NAME
scandir, alphasort - Scans or sorts directory contents LIBRARY
Standard C Library (libc.a) SYNOPSIS
#include <sys/types.h> #include <sys/dir.h> int scandir ( char *dir_name, struct dirent * (*name_list[ ]), int (*select) ( struct dirent *dir ), int (*compare) ( struct dirent **dir1, struct dirent **dir2 ) ); int alphasort ( struct dirent **dir1, struct dirent **dir2 ); PARAMETERS
Points to the directory name. Points to the array of pointers to directory entries. Points to a user-supplied function that is called by the scandir() function to select which entries to include in the array. Points to a user-supplied function that sorts the completed array. Points to a dirent structure. Points to a dirent structure. DESCRIPTION
The scandir() function reads the directory pointed to by the dir_name parameter. It then uses the malloc() function to create an array of pointers to directory entries. The scandir() function returns the number of entries in the array and, through the name_list parameter, a pointer to the array. The select parameter points to a user-supplied function that the scandir() function calls to select which entries to include in the array. The selection routine is passed a pointer to a directory entry and returns a nonzero value for a directory entry that is included in the array. If the select parameter is a null value, all directory entries are included. The compare parameter points to a user-supplied function that is passed to the qsort() function to sort the completed array. If the compare parameter is a null value, the array is not sorted. The memory allocated to the array can be deallocated by freeing each pointer in the array, and the array itself, with the free() function. The alphasort() function alphabetically compares the two dirent structures pointed to by the dir1 and dir2 parameters. This function can be passed as the compare parameter to either the scandir() function or the qsort() function. A user-supplied subroutine may also be used. RETURN VALUES
The scandir() function returns -1 if the directory cannot be opened for reading or if the malloc() function cannot allocate enough memory to hold all the data structures. If successful, the scandir() function returns the number of entries found. The alphasort() function returns the following values: Less than 0 (zero): The dirent structure pointed to by the dir1 parameter is lexi- cally less than the dirent structure pointed to by the dir2 parameter. 0 (zero): The dirent structures pointed to by the dir1 parameter and the dir2 parameter are equal. Greater than 0 (zero): The dirent structure pointed to by the dir1 parameter is lexically greater than the dirent structure pointed to by the dir2 parameter. RELATED INFORMATION
Functions: malloc(3), opendir(3), qsort(3) delim off scandir(3)
All times are GMT -4. The time now is 11:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy