Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Compare files with regular expression Post 302661055 by linuxr on Sunday 24th of June 2012 02:36:02 PM
Old 06-24-2012
Not tried much yet. So far I have tried to understand the meaning of the command 'idx' but search results have not described this command. Example below:

file1:
Code:
text1 10
text2 20

file2:
Code:
text1textabc 10
text2textdef 20
text3textghi 30

awktest:
Code:
#! /bin/awk -f
BEGIN {FS=","}
{idx=$1, [0-9]} FNR==NR{f1[idx];next} idx in f1 file1 file2

Code:
chmod u+x awktest
./awktest file1 file2 > file 3

awk: ./awktest:3: {idx=$1, [0-9]} FNR==NR{f1[idx];next} idx in f1 file1 file2
awk: ./awktest:3:        ^ syntax error
awk: ./awktest:3: {idx=$1, [0-9]} FNR==NR{f1[idx];next} idx in f1 file1 file2
awk: ./awktest:3:              ^ syntax error
awk: ./awktest:3: {idx=$1, [0-9]} FNR==NR{f1[idx];next} idx in f1 file1 file2
awk: ./awktest:3:                                                 ^ syntax error

file3 is empty!

Would like to be able to use regular expression as a criterion to select records that match the criterion and then create a new file in the format of file 2.

Last edited by Scrutinizer; 06-24-2012 at 03:56 PM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

compare variable against regular expression?

is it possible? if so, how? i want to check a variable whether is it a number or letter in an if-else statement (6 Replies)
Discussion started by: finalight
6 Replies

2. Shell Programming and Scripting

AWK - compare $0 to regular expression + variable

Hi, I have this script: awk -v va=45 '$0~va{print}' flo2 That returns: "4526745 1234 " (this is the only line of the file "flo2". However, I would like to get "va" to match the begining of the line, so that is "va" is different than 45 (eg. 67, 12 ...) I would not have any output. That... (3 Replies)
Discussion started by: jolecanard
3 Replies

3. Shell Programming and Scripting

How to apply a regular expression in all the files in a directory

I have say 100 text files (with .txt extension) in a directory. An example of the content in the file is given below "NAME" "cgd1_200" "cgd1_3210" "cgd1_560" "cgd2_2760" "cgd2_290" "cgd3_3210" "cgd3_3310" "cgd3_660" "cgd5_2130" "cgd5_4080" "cgd6_3690" "cgd6_4480" "cgd8_1540"... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

4. Shell Programming and Scripting

Regular Expression to copy files

Hi All, I have a file with the contents as below. Current_path/file1 Current_path/file2 Current_path/file3 Now i want a regular expression to copy this files to cp Current_path/file1 HOME_DIR/Current_path/file1 cp Current_path/file2 HOME_DIR/Current_path/file2 cp Current_path/file3 ... (2 Replies)
Discussion started by: girish.raos
2 Replies

5. Shell Programming and Scripting

search a regular expression and match in two (or more files) using bash

Dear all, I have a specific problem that I don't quite understand how to solve. I have two files, both of the same format: XXXXXX_FIND1 bla bla bla bla bla bla bla bla bla bla bla bla ======== (return) XXXXXX_FIND2 bla bla bla bla bla bla (10 Replies)
Discussion started by: TheTransporter
10 Replies

6. Shell Programming and Scripting

copying files using regular expression

I have 3 files names as HU123.IHS ,SU345.IHS DU567.IHS I have written a script to copy the files to the destination server but I am getting the error. /bin/cp '/dun/homes/11.3.7/packages/HU*.IHS' /dun/homes/11.3.7/Target But I am getting one error :- /bin/cp: cannot stat... (1 Reply)
Discussion started by: maitree
1 Replies

7. Shell Programming and Scripting

How to compare a file name with a regular expression !!

Hi, I need to compare file names in a folder with several strings(which are in regular expression format): For example: there is a file "objectMyHistoryBook" and there are several strings to compare this file name with: objectMyMaths*, objectMyEnglish*, objectMyHistory*,... (2 Replies)
Discussion started by: Lucifer_123
2 Replies

8. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

9. Homework & Coursework Questions

Regular Expression to match files in Perl

Hi Everybody! I need some help with a regular expression in Perl that will match files named messages, but also files named message.1, message.2 and so on. So really I need one that will find messages and messages that might be followed by a period and a digit without matching other files like... (2 Replies)
Discussion started by: Hax0rc1ph3r
2 Replies

10. Shell Programming and Scripting

How to find regular expression for two files?

I have files: sum_<INPUT FILENAME>.YYYYMMDDhhmmss.csv and sum_details_<INPUT FILENAME>.YYYYMMDDhhmmss.csv I have no idea, what is input filename, but in the code I would like to catch them in case I process them in the loop above case statement for *.${Today}.*.txt... (3 Replies)
Discussion started by: digioleg54
3 Replies
spectral-analysis(7)						  Numm Tutorials					      spectral-analysis(7)

NAME
spectral analysis - perform realtime spectral analysis SYNOPSIS
numm-run FILE DESCRIPTION
Frequency makes for a meaningful description of many audio signals. We can use numpy's fourier analysis to compute spectra from the micro- phone and display the results visually. We will break down the process into smaller parts: baby steps... First, create and save a skeletal file that moves a line across the screen: idx = 0 def video_out(a): global idx a[:,idx] = 255 idx = (idx + 1) % a.shape[1] def audio_in(a): pass Save this snippet and run it with numm-run. We will use the numpy.fft module for our analysis. First we define a function to get a particular frequency from the fourier transform: import numpy as np def get_freq(fourier, frequency): freqs = np.fft.fftfreq(len(fourier), 1/44100.0) nearest = (abs(freqs - frequency)).argmin() return abs(fourier[nearest]) Next, we hook up this function to audio input from the microphone. A frequency bin is chosen on a log scale for each row on the screen to display a spectogram. In total: import numpy as np idx = 0 recent_audio = np.zeros(4096, np.int16) recent_video = np.zeros((240,320,3), np.uint8) freq_bins = np.exp2(np.linspace(np.log2(27000),np.log2(27),240)) def get_freq(fourier, frequency): freqs = np.fft.fftfreq(len(fourier), 1/44100.0) nearest = (abs(freqs - frequency)).argmin() return abs(fourier[nearest]) def video_out(a): global idx fourier=np.fft.fft(recent_audio) values =np.array([get_freq(fourier,X) for X in freq_bins]) recent_video[:,idx,1] = (values/10000).clip(0,255) idx = (idx + 1) % a.shape[1] a[:] = np.roll(recent_video, -idx, axis=1) def audio_in(a): recent_audio[:] = np.roll(recent_audio, len(a)) recent_audio[:len(a)] = a.mean(axis=1) SEE ALSO
numm-run(1), numm.getting-started(7), numm.one-bit-instrument(7) numm February 2012 spectral-analysis(7)
All times are GMT -4. The time now is 02:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy