head followed by variable??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting head followed by variable??
# 1  
Old 04-28-2009
head followed by variable??

I know that the common use of head is for example head -3 etc.Is there any possibility that,if i have a variable that equals to an integer(i=5),i can write head -i??
If not,what syntax or commands should i write down in order to have the same result?


//maybe something lik head -"$variable" ?

Last edited by bashuser2; 04-28-2009 at 08:05 AM..
# 2  
Old 04-28-2009
Assuming that you variable is named i, and is set, this should work:
Code:
head -${i} file

# 3  
Old 04-28-2009
ok "$i" seems fine but i will check this too!thnks a lot!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Scratching my head over old post

Hello ! Pondering over some old post & I need some help. Here is the link below - https://www.unix.com/shell-programming-and-scripting/157909-pull-intermediate-strings.html When I run this, echo " process(130) Deleting Text on line 11 (ESN:27723211621B01DJ68AG) because a number... (2 Replies)
Discussion started by: OMLEELA
2 Replies

2. UNIX for Dummies Questions & Answers

Help using head cmd, print 20 then the next 20 etc

Hi all, I have a list of text, single column and I want to print the first 20, then the second 20 and so on. I was pointed to xarg to help with this, but can't get my head around how to use it. Would be great if it would put them into separate files with a certain name. Any suggestions... (2 Replies)
Discussion started by: onfirealot
2 Replies

3. UNIX for Dummies Questions & Answers

find and head -1

i have lots of files in /law/prod and /law/dev, such as AP20PD, AP20WS, AP20.scr, AP20.rpt if i am in /law DIR find . -name AP20PD, found in /law/prod and /law/dev i want to head -1 AP20PD from both location and >> /tmp/test.log can i use find and head in one line ? ----------... (1 Reply)
Discussion started by: tjmannonline
1 Replies

4. OS X (Apple)

Help with head -q option on Mac OS X

I am trying to run a csh script (this is usually done on my Linux machine but it died, so I had to resort to a Mac :eek:) and I received the following error message: head: illegal option --q My script takes multiple files as the input, concatenates them and produces a single file as the... (4 Replies)
Discussion started by: mac_novice
4 Replies

5. Shell Programming and Scripting

head command with more than one file

Hi, I have the following problem. I have files with one column of data (let's say file1.dat, file2.dat...file6.dat), and I would like to record the first value of the column of each file into another file (let's name it fileall.dat), which would have the the six values, one in each column. I use to... (4 Replies)
Discussion started by: josegr
4 Replies

6. Shell Programming and Scripting

cat vs head vs readline get variable from txt file

I have a file with a single filename in it, which I want to assign to a BASH variable, so I've been trying: c=$(head -1 somefile) echo $c which outputs correctly, but them when I do ... somecommand $c it says it can't find the file, is that because it's grabbing the whole line, and... (5 Replies)
Discussion started by: unclecameron
5 Replies

7. Shell Programming and Scripting

head usage

$ct=1 head -n $ct file. When i used like this, i got an error , Bad usage of head Cant we use variables in place of number in HEAD. In my requirement for every iteration i should increase the number in Head and tail the last one. HOw can i achieve this (5 Replies)
Discussion started by: vasuarjula
5 Replies

8. Programming

http HEAD reuest

I have written a c socket programe which can send the http GET request.But it dont work for HEAD reuest.can anyone help me.I am connected to internet via a proxy and the port/ip in the programe are proxies ones -------------------------------------------------- #include <stdlib.h> #include... (3 Replies)
Discussion started by: chamaraHe
3 Replies

9. Shell Programming and Scripting

head command

Hi All, How can the head command be used to extract only a particular line. By default head -n filename displays the first n lines. I want only the nth line. I couldn't get it from forum search. Thanks, Sumesh (6 Replies)
Discussion started by: sumesh.abraham
6 Replies

10. UNIX for Dummies Questions & Answers

help.. I am in way over my head !!!!

my boss has done it again I have been sent to fix a unix issue and I ma hoping you can help three issues 1st. I have a printer that when you try to print to it the print job comes out on a diffrent printer. If I take the printer ( dot matrix thourgh a serail connection) to a diffrent local the... (3 Replies)
Discussion started by: oberon42
3 Replies
Login or Register to Ask a Question