Sponsored Content
Top Forums Shell Programming and Scripting Cut command not working in for loop Post 302863753 by renuk on Tuesday 15th of October 2013 05:15:08 AM
Old 10-15-2013
hi,

i tried this command it is giving below error:
ls -ld GTDA_Dly_Sls_SS_136_20130917.20130917205418.psv
/bin/ls: cannot access GTDA_Dly_Sls_SS_136_20130917.20130917205418.psv: No such file or directory

but my path contains .xls file which contains many files in it..

/dm/RMDW_LandingZone/dev/work_area/ABaC_reregister> more file_GTDA.xls
GTDA_Dly_Pmix_AT_136_20130917.20130917205418.psv
GTDA_Dly_Pmix_AT_136_20130917.20130917205619.psv
GTDA_Dly_Pmix_AT_66_20130917.20130917205619.psv
GTDA_Dly_Pmix_CA_12_20130917.20130917205619.psv
GTDA_Dly_Sls_SS_136_20130917.20130917205418.psv

---------- Post updated at 02:45 PM ---------- Previous update was at 02:32 PM ----------

hi,

the problem is the files which i am passing to temp folder after below command ...

var1=`cat file_GTDA.xls|grep 'GTDA_Dly_Sls_'`
var4="|"
for i in $var1
do
var3=`cut -d "$var4" -f18,19 $i|sort -u`
var2=$var4""$var3
sed -n 's/'"$var2"'//p' $i> ./temp/$i
# sed -e 's/'"$var2"'//p' $i> ./temp/$i
done

excpected files are passed to temp but with 0 bytes./dm/RMDW_LandingZone/dev/work_area/ABaC_reregister/temp> ls -ltr
total 8
drwxrwxrwx 2 mc25730 dstage 4096 2013-10-15 02:59 renamed_files
-rw-rw-r-- 1 mc25730 dstage 0 2013-10-15 02:59 GTDA_Dly_Sls_SS_136_20130917.20130917205418.psv
-rw-rw-r-- 1 mc25730 dstage 0 2013-10-15 02:59 GTDA_Dly_Pmix_CA_12_20130917.20130917205619.psv
-rw-rw-r-- 1 mc25730 dstage 0 2013-10-15 02:59 GTDA_Dly_Pmix_AT_66_20130917.20130917205619.psv
-rw-rw-r-- 1 mc25730 dstage 0 2013-10-15 02:59 GTDA_Dly_Pmix_AT_136_20130917.20130917205619.psv
-rw-rw-r-- 1 mc25730 dstage 0 2013-10-15 02:59 GTDA_Dly_Pmix_AT_136_20130917.20130917205418.psv

i think problem is coming while i pass variable in cut and sed command ..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use loop var i within Cut Command

Hi, In the following bash code rather than cutting at a predefined character I would like to cut at position i (i var from loop). Is this possible? I have tried eval, but either it's not possible or my syntax is wrong. thanks Nick for i in {1..9} do theChar=$(echo... (3 Replies)
Discussion started by: de_la_espada
3 Replies

2. UNIX for Dummies Questions & Answers

Cut not working in a loop

I have a function "MyPrint" that runs great on a file (BaseData.txt) that has one line of data. If i add rows to the text file it's reading the tFile variable becomes a list of every field 2 in the file. To correct this, i tried to call the function from a loop where i read one line at a time and... (4 Replies)
Discussion started by: KME
4 Replies

3. Shell Programming and Scripting

cut the present working directory

how to traverse through each directory (1 Reply)
Discussion started by: Reddy482
1 Replies

4. UNIX for Dummies Questions & Answers

cut not working the way i want it to

Hi Forum Im having problem with cut it even when i cut a field from an input file eg echo $x | cut -f1 -d':' it doesnt read the whole line if there is a space in it eg thisLineHasA SpaceInIt :wall: it only read up to the space.What i want is so the it cut the field as one line ... (8 Replies)
Discussion started by: ShinTec
8 Replies

5. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

6. UNIX for Dummies Questions & Answers

Cut command, no input delim, output delim not working

Hello, I'm using cygwin on my Windows 7 machine. From the man pages of cut: --output-delimiter=STRING use STRING as the output delimiter the default is to use the input delimiter I tried the following commands and got the error messages: $ cut -c1-10,20-30 -d... (10 Replies)
Discussion started by: kojac
10 Replies

7. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

8. Shell Programming and Scripting

CUT command not giving correct result inside loop

Hi, i have a source file and have 3 columns and separated by "|" .i want to split this 3 columns in different variable.When i am executing this values indivisually giving correct result but when the same execute inside a for loop,it's giving issues. Src file(jjj.txt) -------... (8 Replies)
Discussion started by: raju2016
8 Replies

9. UNIX for Beginners Questions & Answers

Mv command in for loop - not working

HI Folks - I'm very frustrated - I'm trying to execute a verys imple for loop and rename the files if they exist. here is my loop : ydate=`TZ=aaa24 date +%m%d` CR_YR=$(date "+%Y") echo $ydate echo ${CR_YR} cd... (6 Replies)
Discussion started by: SIMMS7400
6 Replies

10. Shell Programming and Scripting

Why is my cut command not working ?

OS : RHEL 6.8 Shell : bash I want to remove all lines like below from the history output as it has password. $ history | grep sqlplus 239 sqlplus jn_usr/dxc825#@10.5.12.106/OCSGPD 256 sqlplus osb_soa/KD1egM09@10.5.12.196/BSOAPRD 279 sqlplus jn_usr/dxc825#@10.80.16.219/OCSGPD... (5 Replies)
Discussion started by: John K
5 Replies
SDL_PixelFormat(3)						 SDL API Reference						SDL_PixelFormat(3)

NAME
SDL_PixelFormat - Stores surface format information STRUCTURE DEFINITION
typedef struct SDL_PixelFormat { SDL_Palette *palette; Uint8 BitsPerPixel; Uint8 BytesPerPixel; Uint8 Rloss, Gloss, Bloss, Aloss; Uint8 Rshift, Gshift, Bshift, Ashift; Uint32 Rmask, Gmask, Bmask, Amask; Uint32 colorkey; Uint8 alpha; } SDL_PixelFormat; STRUCTURE DATA
palette Pointer to the palette, or NULL if the BitsPerPixel>8 BitsPerPixel The number of bits used to represent each pixel in a surface. Usually 8, 16, 24 or 32. BytesPerPixel The number of bytes used to represent each pixel in a surface. Usually one to four. [RGBA]mask Binary mask used to retrieve individual color values [RGBA]loss Precision loss of each color component (2^[RGBA]loss) [RGBA]shift Binary left shift of each color component in the pixel value colorkey Pixel value of transparent pixels alpha Overall surface alpha value DESCRIPTION
A SDL_PixelFormat describes the format of the pixel data stored at the pixels field of a SDL_Surface. Every surface stores a SDL_PixelFor- mat in the format field. If you wish to do pixel level modifications on a surface, then understanding how SDL stores its color information is essential. 8-bit pixel formats are the easiest to understand. Since its an 8-bit format, we have 8 BitsPerPixel and 1 BytesPerPixel. Since BytesPer- Pixel is 1, all pixels are represented by a Uint8 which contains an index into palette->colors. So, to determine the color of a pixel in a 8-bit surface: we read the color index from surface->pixels and we use that index to read the SDL_Color structure from surface->for- mat->palette->colors. Like so: SDL_Surface *surface; SDL_PixelFormat *fmt; SDL_Color *color; Uint8 index; . . /* Create surface */ . . fmt=surface->format; /* Check the bitdepth of the surface */ if(fmt->BitsPerPixel!=8){ fprintf(stderr, "Not an 8-bit surface. "); return(-1); } /* Lock the surface */ SDL_LockSurface(surface); /* Get the topleft pixel */ index=*(Uint8 *)surface->pixels; color=fmt->palette->colors[index]; /* Unlock the surface */ SDL_UnlockSurface(surface); printf("Pixel Color-> Red: %d, Green: %d, Blue: %d. Index: %d ", color->r, color->g, color->b, index); . . Pixel formats above 8-bit are an entirely different experience. They are considered to be "TrueColor" formats and the color information is stored in the pixels themselves, not in a palette. The mask, shift and loss fields tell us how the color information is encoded. The mask fields allow us to isolate each color component, the shift fields tell us the number of bits to the right of each component in the pixel value and the loss fields tell us the number of bits lost from each component when packing 8-bit color component in a pixel. /* Extracting color components from a 32-bit color value */ SDL_PixelFormat *fmt; SDL_Surface *surface; Uint32 temp, pixel; Uint8 red, green, blue, alpha; . . . fmt=surface->format; SDL_LockSurface(surface); pixel=*((Uint32*)surface->pixels); SDL_UnlockSurface(surface); /* Get Red component */ temp=pixel&fmt->Rmask; /* Isolate red component */ temp=temp>>fmt->Rshift;/* Shift it down to 8-bit */ temp=temp<<fmt->Rloss; /* Expand to a full 8-bit number */ red=(Uint8)temp; /* Get Green component */ temp=pixel&fmt->Gmask; /* Isolate green component */ temp=temp>>fmt->Gshift;/* Shift it down to 8-bit */ temp=temp<<fmt->Gloss; /* Expand to a full 8-bit number */ green=(Uint8)temp; /* Get Blue component */ temp=pixel&fmt->Bmask; /* Isolate blue component */ temp=temp>>fmt->Bshift;/* Shift it down to 8-bit */ temp=temp<<fmt->Bloss; /* Expand to a full 8-bit number */ blue=(Uint8)temp; /* Get Alpha component */ temp=pixel&fmt->Amask; /* Isolate alpha component */ temp=temp>>fmt->Ashift;/* Shift it down to 8-bit */ temp=temp<<fmt->Aloss; /* Expand to a full 8-bit number */ alpha=(Uint8)temp; printf("Pixel Color -> R: %d, G: %d, B: %d, A: %d ", red, green, blue, alpha); . . . SEE ALSO
SDL_Surface, SDL_MapRGB SDL
Tue 11 Sep 2001, 23:01 SDL_PixelFormat(3)
All times are GMT -4. The time now is 11:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy