Sponsored Content
Top Forums Shell Programming and Scripting Creating new file inside a for loop Post 302954548 by mac4rfree on Wednesday 9th of September 2015 01:35:51 AM
Old 09-09-2015
Creating new file inside a for loop

Hi,

I have list of files present in a folder. I want to search for a particular keyword sequentially and create a file which will be later used by some other program.
Input files:
Code:
[mac]$ ls
a.dsx  b.dsx  c.dsx  Dataline_.txt  Dataline.txt  loop.sh
[ mac]$ cat *.dsx
help

tyiis
global

Code:
for i in `ls *.dsx`
do
grep 'help' $i > Dataline.txt;
mv Dataline.txt Dataline_$1.txt;
done

When i am executing this, i can see grep command is getting executed for all the files sequentially but the output is not getting captured in Dataline.txt

Code:
ls *.dsx
++ ls a.dsx b.dsx c.dsx
+ for i in '`ls *.dsx`'
+ grep help a.dsx
+ mv Dataline.txt Dataline_.txt
+ for i in '`ls *.dsx`'
+ grep help b.dsx
+ mv Dataline.txt Dataline_.txt
+ for i in '`ls *.dsx`'
+ grep help c.dsx
+ mv Dataline.txt Dataline_.txt

Can somebody point out as what i am doing wrong.

Cheers!!!

---------- Post updated at 11:05 AM ---------- Previous update was at 10:46 AM ----------

Sorry, I found the solution. The script is working as expected.

Code:
for i in `ls *.dsx`
do
grep 'help' $i > Dataline.txt;
cat Dataline.txt;
awk '{ print FNR "|" $0 }' Dataline.txt > DataLine1.txt;
cat DataLine1.txt;
done

The above is working code. Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating a file inside a script

Hi, How can I create a file inside a script. The thing is that, I have to create the file inside the script and it will be acting as a log file the script.Whenever I execute the script the file has to be created and the output has to be directed into that file. Tahnks in advance (11 Replies)
Discussion started by: sendhilmani
11 Replies

2. Shell Programming and Scripting

file creation inside loop

i=1 while do touch TC$i.txt i=`expr $1 + 1` done echo "files created successfully" What is wrong with code...its running continuosly... (4 Replies)
Discussion started by: villain41
4 Replies

3. Shell Programming and Scripting

variable inside variable inside loop headache

Hi Gurus I have a file called /tmp/CMDB which looks like this serial: 0623AN1208 hostname: server1 model: x4100 assetID: 1234 I am writing a for loop that will go through this file line by line creating a variable of itself. Using the first iteration of the loop (i.e. the first line) as... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

4. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

5. Shell Programming and Scripting

BASH loop inside a loop question

Hi all Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies

6. Shell Programming and Scripting

Update file record inside read loop

Hi, I am reading file records inside a while loop, and want to update the record when certain condition is met. How can I update a file while being read? I want to avoid using temporary files, copy, rename, ... while IFS=',' read -r f1 f2 do function(f1,f2) if then <add... (1 Reply)
Discussion started by: ysrini
1 Replies

7. Shell Programming and Scripting

Creating loops inside a file and extracting and loading data

Help needed (1 Reply)
Discussion started by: Chand Shrestha
1 Replies

8. Shell Programming and Scripting

If inside If loop

Hi All, Below is the very simple code snippet but it si giving me syntax error #!/bin/bash #To ensure If JMS directory exists or not ServerName=$(hostname) #To ensure If JMS directory exists or not echo $ServerName if ; then echo "Inside First If" if ; then echo 'JMS... (4 Replies)
Discussion started by: sharsour
4 Replies

9. UNIX for Dummies Questions & Answers

Write a while loop inside for loop?

I'm taking a unix class and need to countdown to 0 from whatever number the user inputs. I know how to do this with a while or until loop but using the for loop is throwing me off.... I know I can use an if-then statement in my for loop but can I include a while loop in my for loop? (3 Replies)
Discussion started by: xxhieixx
3 Replies

10. Shell Programming and Scripting

Problem while displaying(cat) file content inside telnet loop .

Hi Team, Not getting the file output inside my email which i am sending from unix box. . Please refer the below code : #!/bin/sh { sleep 5 echo ehlo 10.56.185.13 sleep 3 echo mail from: oraairtel@CNDBMUREAPZP02.localdomain sleep 3 echo rcpt to: saurabhtripathi@anniksystems.com... (1 Reply)
Discussion started by: tripathi1990
1 Replies
grcompiler(1)															     grcompiler(1)

NAME
grcompiler - Compile GDL into a TrueType Font SYNOPSIS
grcompiler [-d] [-D] [-g] [-n number] [-v number] [-w number] [-wall] [-q] gdl-file font-file [output-file] [output-fontname] Description Grcompiler compiles a Graphite Description Language description of the smarts for a font along with a TrueType Font to create a graphite font with graphite tables in it. -d Generate XML debugger file. -D Generate all debugger files. -g Permit and ignore invalid glyph definitions. -nnumber Set name table start location. -q Quiet mode (no messages except on error). -vnumber Set Silf table version number. -wnnnn Ignore warning with the given number. This option may be repeated. -wall Display all warnings. Environment grcompiler makes use of the following environment variables GDLPP Specifies the command to execute to run the GDL preprocessor Files gdlerr.txt Warnings and errors are output to this file. dbg_classes.txt Debug file that specifies the classes stored in the font in terms of their GDL source and containing glyph ids in hex. dbg_cmap.txt Debug file giving Unicode to glyph mapping of all the glyphs in the font and vice versa. dbg_enginecode.txt Debug file containing the action code and constraint code associated with each pass and rule in a pass. dbg_fsm.txt Debug file that gives the finite state machines of each pass and the rules referenced. For each pass, a mapping is given between glyph and column number. dbg_glyphattrs.txt Debug file containing all the glyph attributes and their names, along with values specified for each glyph. dbg_parsetree.txt Debug file giving the complete parse tree of the GDL source file. dbg_ruleprec.txt Debug file that lists the rules in precedence order (order in which they will be tested) for each pass. $_temp.gdl Debug file containing the output of gdlpp Author Martin Hosken <mhosken@users.sourceforge.net> $Date: 2012-05-29 11:36:50 $ grcompiler(1)
All times are GMT -4. The time now is 08:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy