How to modify the script to include cat function


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to modify the script to include cat function
# 1  
Old 10-24-2012
How to modify the script to include cat function

I have the following script that greps lines containing "AT" from data files data1.hsq through data1000.hsq, then cuts their second column and puts in data files called perm1 through perm1000.

I want to modify the script so that instead of putting the data in separate data files perm1 through perm1000, it concatenates them into a single data file. So essentially the same effect as using cat to concatenate perm1 through perm1000. How do I go about doing that? Thanks!

Code:
for i in {1..1000}
do
grep "AT"  data$i.hsq | cut -f2 > perm$i
done

# 2  
Old 10-24-2012
try:
Code:
for i in {1..1000}
do
grep "AT"  data$i.hsq | cut -f2
done >> new_file

This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 10-24-2012
Code:
awk -F'\t' '/AT/{print $2}' data{1..1000}.hsq > datafile

---------- Post updated at 11:19 AM ---------- Previous update was at 11:11 AM ----------

Quote:
Originally Posted by rdrtx1
try:
Code:
for i in {1..1000}
do
grep "AT"  data$i.hsq | cut -f2
done >> new_file

newfile will remain open for the duration of the loop so there is no need to use >> unless it is required to append all the data written to standard output by the loop statements, to the already existing file new_file.
This User Gave Thanks to elixir_sinari For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to modify the cat command to highlight a chosen word?

Hi, I'm fairly new to programming and was just wondering... Is it possible to modify the cat command (using a linux virtual machine) so that it displays text of a file and highlights a specifically chosen word? I've been looking for how to do it on the internet and can't find any helpful... (3 Replies)
Discussion started by: IndigoFox
3 Replies

2. Shell Programming and Scripting

Help to Modify File Name in each function before calling another function.

I have a script which does gunzip, zip and untar. Input to the script is file name and file directory (where file is located) I am reading the input parameters as follows: FILENAME=$1 FILEDIR=$2 I have created 3 functions that are as follows: 1) gunzip file 2) unzip file... (2 Replies)
Discussion started by: pinnacle
2 Replies

3. Homework & Coursework Questions

C++ Attempting to modify this function to read from a (;) semi-colon-separated file

After some thought. I am uncomfortable issuing my professors name where, there may be unintended side effects from any negative responses/feedback. Willing to re post if I can omit school / professor publicly, but can message moderator for validation? I am here for knowledge and understanding,... (1 Reply)
Discussion started by: briandanielz
1 Replies

4. Shell Programming and Scripting

How can I modify my script to include or substitute missing data?

Let me start off by saying I am a self taught sometimes scripter so what you will see below won't be pretty. I have created a script to parse through a file with a large amount of data and simply pull out what I need. In doing this I create several files and then paste them together in order to... (2 Replies)
Discussion started by: fsanchez
2 Replies

5. Shell Programming and Scripting

Calling Pl/sql function in shell script to modify csv

I need to 1.Open a csv 2.Process the csv i.e. Modify 2 column in the csv. To modify the column the value needs to be passed to a pl/sql function and the return value should be updated For eg: If column 2 E,then E will be passed in database function which will return Employee. 3. Write a... (5 Replies)
Discussion started by: Chinky23
5 Replies

6. Shell Programming and Scripting

how to include a text pattern in system function in PERL

Pleeeeease help.. I'm working in perl i have a system function to check whether a file is readable for others or not. i just want to print a text in that command my command is : system ("ls -la $filename | awk '\$1~ /^-......r../ {print \$9}'"); i know for displaying text in awk... (6 Replies)
Discussion started by: shubhamsachdeva
6 Replies

7. Shell Programming and Scripting

cat arguments to a function

Hi, I've a logging function in bourne shell, flog() which logs the first argument passed to it. How can I pass arguments to this function from a file, like cat filename | sed '...filtering...' | flog or cat filename | sed '...filtering...' | xargs flog Which did not work, after which... (3 Replies)
Discussion started by: Random_Net
3 Replies

8. UNIX for Dummies Questions & Answers

[solved] Script creation (how to include options in the script)

Hi guys i have written a script which takes the options given to him and execute itself accordingly. for example if a script name is doctortux then executing doctortux without option should made doctortux to be executed in automatic mode i.e. doctortux -a or if a doctortux is needed to run in... (4 Replies)
Discussion started by: pinga123
4 Replies

9. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies

10. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies
Login or Register to Ask a Question