smart question


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users smart question
# 1  
Old 06-30-2005
Question smart question

eg. : there is a file - 322 bytes,
how can I (or you) view just a half of file (161 bytes)?
# 2  
Old 06-30-2005
what if the size of the file is odd number
# 3  
Old 06-30-2005
assuming your input file is in_file. You could code something like this

Code:
#! /usr/bin/ksh

size=$(wc -c in_file | awk -F " " '{print $1}')
half_size=`expr $size / 2`
split -b $half_size in_file

The result of the final split command will be two or three files name xaa, xab and xac. you will get two files if the in_file is even number in size else three files with the last file xac being just 1 byte.
If you wanted the first half just read xaa, else read xab and xac if available for the latter.

jerardfjay

Last edited by jerardfjay; 06-30-2005 at 04:48 PM.. Reason: more explanation
# 4  
Old 06-30-2005
try:
Code:
 head -c -n 168 filename

This prints the first 168 bytes in the file.
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need smart script !

Hi, I need a script to assign variables the below paths /appl/user_projects/domains/<xxx>/servers/<yyy>/logs Where <xxx> can be any number and name of directories. <yyy> can be another set of any number of names and directories. I want to neglect all the <xxx> and <yyy>... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. UNIX for Dummies Questions & Answers

Explain the difference between the commands cd ~smart and cd ~/smart

Is it possible for both commands to work? (1 Reply)
Discussion started by: phunkypants
1 Replies

3. Shell Programming and Scripting

smart script?

First, I know that's a bad title. I couldn't think of anything short enough. ... I wrote the following script to let me know when various parts of the network are down. It used to look like this before last weekend when I got over 500 emails about 1 host being down all weekend: this is in the... (1 Reply)
Discussion started by: raidzero
1 Replies

4. UNIX for Advanced & Expert Users

Real smart question

hello My question is whats the difference between LP and LPR to print Sun Solaris ? lp -dprintername postscriptfile.ps or lpr -Pprintname postscriptfile.ps (2 Replies)
Discussion started by: Peterh
2 Replies
Login or Register to Ask a Question