Visit Our UNIX and Linux User Community


Considerable trouble with for loop in combination with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Considerable trouble with for loop in combination with awk
# 1  
Old 05-14-2014
Considerable trouble with for loop in combination with awk

I have the text file where each line has the format:

chr10 101418889 101418904 0.816327

Right now the interval between column 2 and 3 is 15. I only want the two consecutive positions starting at position 1, write it to a file, then move up one position write to file etc. So that:

File 1: chr10 101418889 101418990 0.816327
File 2: chr10 101418890 101418991 0.816327
File 3: chr10 101418891 101418992 0.816327
and so on...

My code so far:
Code:
for ((i = 0; i <= 14; ++1)) do
awk -v h=$i '{$2 += h; $3 += h-14; print}' original_core_files/lung.core.low.5SitesMin.bed > ../core_motif_singleton_controls/script/$i.bed;
done

The output is a "0.bed" file and a stuck loop.

As you probably see my programming experience is very limited, thank you very much for any form of help!

---------- Post updated at 04:36 AM ---------- Previous update was at 04:29 AM ----------

Solved:
naturally I should have put i++ instead of ++1, is there a way to delete embarrassing threads like this one?
# 2  
Old 05-14-2014
Moderators can do that if you need. You can request for it in Post Here to Contact Site Administrators and Moderators forum.

Alternatively, you can also mark the thread as 'solved' by adding "solved" tag to it. I just did it for you.
Also, you can do by adding "[Solved]" to the subject.

Previous Thread | Next Thread
Test Your Knowledge in Computers #569
Difficulty: Medium
foreach loops are considered syntactic sugar.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combination awk and rename

Hello, i wondering if anybody can help me with the following: doing a search for the words "Sample ID:" in a file called test.txt and I need to have the string after this (Postmatch) Then I want that the string is used to rename an other file called test.pdf into .... the string.pdf I... (8 Replies)
Discussion started by: pcdok
8 Replies

2. UNIX for Dummies Questions & Answers

Trouble understand and using for loop

Good evening all I have what might be a simple problem to solve but I do not know how to solve it myself. I am writing a bash script and my code looks something like this: mp3=`ls | grep \.mp3` for f in $mp3 do echo $f done Basically what I want to do is look through the current... (4 Replies)
Discussion started by: mistsong1
4 Replies

3. Programming

trouble with loop counting

HI there, I am trying to count manually what this code does but I am stuck and I don't learly see the result. The code works and it compiles and runs but I just don't follow the value of var. #include<stdio.h> #include<stdlib.h> #include<sys/types.h> #include<unistd.h> #include<wait.h>... (2 Replies)
Discussion started by: bluetxxth
2 Replies

4. Shell Programming and Scripting

help with awk for file combination

1)file1: | *Local Communication Bandwidths (MB/Sec) | Memory copy (bcopy) | | ^ | mmap_bandwidth | | ^ | mmap_read bandwidth | | ^ | memory write bandwidth | | Local Communication Latencies | Pipe Latency | 2)file2 422.6903 1948.9000 ... (9 Replies)
Discussion started by: yanglei_fage
9 Replies

5. Shell Programming and Scripting

Trouble with a file path as awk output in for loop

When I run the following command in the shell it works fine. It prints a city name and then a path for a file. ~$ for i in `awk -F':' '{print $0}' /home/knoppix/Desktop/data/subs | grep -m 1 $ city | sed "s/:/ /"` >do >echo $i >done Now, when I place it in this shell script (sh) it prints... (6 Replies)
Discussion started by: afroCluster
6 Replies

6. Shell Programming and Scripting

Sed Awk Cut Grep Combination Help ?

I have been reading for a few hours trying to educate myself enough to accomplish this task, so please know I have performed some research. Unfortunately, I am not a *NIX scripting expert, or a coder. I come from a network background instead. SO, here is my desired outcome. I have some Cisco... (5 Replies)
Discussion started by: abbzer0
5 Replies

7. Shell Programming and Scripting

for loop syntax trouble

i don't get what's wrong here. i'm writing a shell script that takes 1 argument (a number) from the command-line, but it's throwing an error: Syntax error: Bad for loop variable doesn't make much sense for (( i = 1; i = ${1}; i++ )) # error points to this line everytime do echo... (9 Replies)
Discussion started by: visitorQ
9 Replies

8. Shell Programming and Scripting

Loop Trouble

Can anyone tell me what's wrong with my code here? I'm experiencing weird behavior... I am using 'j' to go down a list filenames saved in a .txt file and prompting the user whether or not she would like to delete each one. This works all well and fine the first run through, but then instead of... (2 Replies)
Discussion started by: RSymphony
2 Replies

9. Shell Programming and Scripting

Start more than one database - trouble with for loop

I have seen this done before - and maybe there is a better way too. I want to be abe to use a for loop (or other better method) to loop through the database instance names that are part of the script - not an external file where a read might be ok. Here is what I have and I know won't work -... (5 Replies)
Discussion started by: dave-mentor
5 Replies

10. UNIX for Dummies Questions & Answers

awk and file combination

Hi there, I have 3 files and i want to take different fields from each file and combine them in one. I would like to ask if somebody tell me how can I refer to each field of the different files to write an awk command. I mean can I do sth like awk '........... print $1.file1 $3.file2}'... (1 Reply)
Discussion started by: sickboy
1 Replies

Featured Tech Videos